Fix inconsistencies uncovered by --enforceReadonly
This commit is contained in:
Родитель
4d1a5ff0a4
Коммит
5cf719a3ad
|
@ -2320,7 +2320,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
|||
}
|
||||
|
||||
function bindModuleDeclaration(node: ModuleDeclaration) {
|
||||
setExportContextFlag(node);
|
||||
setExportContextFlag(node as Mutable<ModuleDeclaration>);
|
||||
if (isAmbientModule(node)) {
|
||||
if (hasSyntacticModifier(node, ModifierFlags.Export)) {
|
||||
errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible);
|
||||
|
@ -2778,7 +2778,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
|||
bindChildren(node);
|
||||
}
|
||||
else {
|
||||
bindContainer(node as HasContainerFlags, containerFlags);
|
||||
bindContainer(node as Mutable<HasContainerFlags>, containerFlags);
|
||||
}
|
||||
parent = saveParent;
|
||||
}
|
||||
|
@ -3091,7 +3091,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
|||
}
|
||||
|
||||
function bindSourceFileIfExternalModule() {
|
||||
setExportContextFlag(file);
|
||||
setExportContextFlag(file as Mutable<SourceFile>);
|
||||
if (isExternalModule(file)) {
|
||||
bindSourceFileAsExternalModule();
|
||||
}
|
||||
|
|
|
@ -291,7 +291,7 @@ export namespace BuilderState {
|
|||
/**
|
||||
* Returns true if oldState is reusable, that is the emitKind = module/non module has not changed
|
||||
*/
|
||||
export function canReuseOldState(newReferencedMap: ReadonlyManyToManyPathMap | undefined, oldState: BuilderState | undefined) {
|
||||
export function canReuseOldState(newReferencedMap: ReadonlyManyToManyPathMap | undefined, oldState: Readonly<BuilderState> | undefined) {
|
||||
return oldState && !oldState.referencedMap === !newReferencedMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -2515,7 +2515,7 @@ export interface TSConfig {
|
|||
/** @internal */
|
||||
export interface ConvertToTSConfigHost {
|
||||
getCurrentDirectory(): string;
|
||||
useCaseSensitiveFileNames: boolean;
|
||||
readonly useCaseSensitiveFileNames: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1299,7 +1299,7 @@ export function getProperty<T>(map: MapLike<T>, key: string): T | undefined {
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
export function getOwnKeys<T>(map: MapLike<T>): string[] {
|
||||
export function getOwnKeys<T>(map: Readonly<MapLike<T>>): string[] {
|
||||
const keys: string[] = [];
|
||||
for (const key in map) {
|
||||
if (hasOwnProperty.call(map, key)) {
|
||||
|
|
|
@ -350,6 +350,7 @@ import {
|
|||
rangeIsOnSingleLine,
|
||||
rangeStartPositionsAreOnSameLine,
|
||||
readJsonOrUndefined,
|
||||
ReadonlyTextRange,
|
||||
removeFileExtension,
|
||||
resolvePath,
|
||||
RestTypeNode,
|
||||
|
@ -4629,7 +4630,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
|||
*
|
||||
* NOTE: You probably don't want to call this directly and should be using `emitList` or `emitExpressionList` instead.
|
||||
*/
|
||||
function emitNodeListItems<Child extends Node>(emit: EmitFunction, parentNode: Node | undefined, children: readonly Child[], format: ListFormat, parenthesizerRule: ParenthesizerRuleOrSelector<Child> | undefined, start: number, count: number, hasTrailingComma: boolean, childrenTextRange: TextRange | undefined) {
|
||||
function emitNodeListItems<Child extends Node>(emit: EmitFunction, parentNode: Node | undefined, children: readonly Child[], format: ListFormat, parenthesizerRule: ParenthesizerRuleOrSelector<Child> | undefined, start: number, count: number, hasTrailingComma: boolean, childrenTextRange: ReadonlyTextRange | undefined) {
|
||||
// Write the opening line terminator or leading whitespace.
|
||||
const mayEmitInterveningComments = (format & ListFormat.NoInterveningComments) === 0;
|
||||
let shouldEmitInterveningComments = mayEmitInterveningComments;
|
||||
|
@ -5010,7 +5011,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
|||
return format & ListFormat.MultiLine ? 1 : 0;
|
||||
}
|
||||
|
||||
function getClosingLineTerminatorCount(parentNode: Node | undefined, lastChild: Node | undefined, format: ListFormat, childrenTextRange: TextRange | undefined): number {
|
||||
function getClosingLineTerminatorCount(parentNode: Node | undefined, lastChild: Node | undefined, format: ListFormat, childrenTextRange: ReadonlyTextRange | undefined): number {
|
||||
if (format & ListFormat.PreserveLines || preserveSourceNewlines) {
|
||||
if (format & ListFormat.PreferNewLine) {
|
||||
return 1;
|
||||
|
@ -5822,7 +5823,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
|||
: `//${comment.text}`;
|
||||
}
|
||||
|
||||
function emitBodyWithDetachedComments<T extends Node>(node: T, detachedRange: TextRange, emitCallback: (node: T) => void) {
|
||||
function emitBodyWithDetachedComments<T extends Node>(node: T, detachedRange: ReadonlyTextRange, emitCallback: (node: T) => void) {
|
||||
enterComment();
|
||||
const { pos, end } = detachedRange;
|
||||
const emitFlags = getEmitFlags(node);
|
||||
|
@ -6042,7 +6043,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
|||
forEachLeadingCommentRange(currentSourceFile.text, pos, cb, /*state*/ pos);
|
||||
}
|
||||
|
||||
function emitDetachedCommentsAndUpdateCommentsInfo(range: TextRange) {
|
||||
function emitDetachedCommentsAndUpdateCommentsInfo(range: ReadonlyTextRange) {
|
||||
const currentDetachedCommentInfo = currentSourceFile && emitDetachedComments(currentSourceFile.text, getCurrentLineMap(), writer, emitComment, range, newLine, commentsDisabled);
|
||||
if (currentDetachedCommentInfo) {
|
||||
if (detachedCommentsInfo) {
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
ObjectLiteralElementLike,
|
||||
ParameterDeclaration,
|
||||
PrivateIdentifier,
|
||||
ReadonlyTextRange,
|
||||
ScriptTarget,
|
||||
setEmitFlags,
|
||||
setInternalEmitFlags,
|
||||
|
@ -113,7 +114,7 @@ export interface EmitHelperFactory {
|
|||
createAsyncDelegatorHelper(expression: Expression): Expression;
|
||||
createAsyncValuesHelper(expression: Expression): Expression;
|
||||
// ES2018 Destructuring Helpers
|
||||
createRestHelper(value: Expression, elements: readonly BindingOrAssignmentElement[], computedTempVariables: readonly Expression[] | undefined, location: TextRange): Expression;
|
||||
createRestHelper(value: Expression, elements: readonly BindingOrAssignmentElement[], computedTempVariables: readonly Expression[] | undefined, location: ReadonlyTextRange): Expression;
|
||||
// ES2017 Helpers
|
||||
createAwaiterHelper(hasLexicalThis: boolean, argumentsExpression: Expression | undefined, promiseConstructor: EntityName | Expression | undefined, parameters: readonly ParameterDeclaration[] | undefined, body: Block): Expression;
|
||||
// ES2015 Helpers
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
NodeArray,
|
||||
orderedRemoveItem,
|
||||
PrivateIdentifier,
|
||||
ReadonlyTextRange,
|
||||
SnippetElement,
|
||||
some,
|
||||
SourceFile,
|
||||
|
@ -180,14 +181,14 @@ export function setStartsOnNewLine<T extends Node>(node: T, newLine: boolean) {
|
|||
/**
|
||||
* Gets a custom text range to use when emitting comments.
|
||||
*/
|
||||
export function getCommentRange(node: Node): TextRange {
|
||||
export function getCommentRange(node: Node): ReadonlyTextRange {
|
||||
return node.emitNode?.commentRange ?? node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a custom text range to use when emitting comments.
|
||||
*/
|
||||
export function setCommentRange<T extends Node>(node: T, range: TextRange) {
|
||||
export function setCommentRange<T extends Node>(node: T, range: ReadonlyTextRange) {
|
||||
getOrCreateEmitNode(node).commentRange = range;
|
||||
return node;
|
||||
}
|
||||
|
|
|
@ -373,6 +373,7 @@ import {
|
|||
QuestionDotToken,
|
||||
QuestionToken,
|
||||
ReadonlyKeyword,
|
||||
ReadonlyTextRange,
|
||||
RedirectInfo,
|
||||
reduceLeft,
|
||||
RegularExpressionLiteral,
|
||||
|
@ -505,8 +506,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
const getJSDocPrePostfixUnaryTypeUpdateFunction = memoizeOne(<T extends JSDocType & { readonly type: TypeNode | undefined; readonly postfix: boolean; }>(kind: T["kind"]) => (node: T, type: T["type"]) => updateJSDocPrePostfixUnaryTypeWorker<T>(kind, node, type));
|
||||
const getJSDocSimpleTagCreateFunction = memoizeOne(<T extends JSDocTag>(kind: T["kind"]) => (tagName: Identifier | undefined, comment?: NodeArray<JSDocComment>) => createJSDocSimpleTagWorker(kind, tagName, comment));
|
||||
const getJSDocSimpleTagUpdateFunction = memoizeOne(<T extends JSDocTag>(kind: T["kind"]) => (node: T, tagName: Identifier | undefined, comment?: NodeArray<JSDocComment>) => updateJSDocSimpleTagWorker(kind, node, tagName, comment));
|
||||
const getJSDocTypeLikeTagCreateFunction = memoizeOne(<T extends JSDocTag & { typeExpression?: JSDocTypeExpression; }>(kind: T["kind"]) => (tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: NodeArray<JSDocComment>) => createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment));
|
||||
const getJSDocTypeLikeTagUpdateFunction = memoizeOne(<T extends JSDocTag & { typeExpression?: JSDocTypeExpression; }>(kind: T["kind"]) => (node: T, tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: NodeArray<JSDocComment>) => updateJSDocTypeLikeTagWorker(kind, node, tagName, typeExpression, comment));
|
||||
const getJSDocTypeLikeTagCreateFunction = memoizeOne(<T extends JSDocTag & { readonly typeExpression?: JSDocTypeExpression; }>(kind: T["kind"]) => (tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: NodeArray<JSDocComment>) => createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment));
|
||||
const getJSDocTypeLikeTagUpdateFunction = memoizeOne(<T extends JSDocTag & { readonly typeExpression?: JSDocTypeExpression; }>(kind: T["kind"]) => (node: T, tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: NodeArray<JSDocComment>) => updateJSDocTypeLikeTagWorker(kind, node, tagName, typeExpression, comment));
|
||||
|
||||
const factory: NodeFactory = {
|
||||
get parenthesizer() {
|
||||
|
@ -1214,10 +1215,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
return node;
|
||||
}
|
||||
|
||||
function finishUpdateBaseSignatureDeclaration<T extends SignatureDeclarationBase>(updated: Mutable<T>, original: T) {
|
||||
function finishUpdateBaseSignatureDeclaration<T extends SignatureDeclarationBase>(updated: T, original: T) {
|
||||
if (updated !== original) {
|
||||
// copy children used for quick info
|
||||
updated.typeArguments = original.typeArguments;
|
||||
(updated as Mutable<T>).typeArguments = original.typeArguments;
|
||||
}
|
||||
return update(updated, original);
|
||||
}
|
||||
|
@ -1507,7 +1508,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
if (transformFlags) {
|
||||
node.transformFlags |= transformFlags;
|
||||
}
|
||||
return node;
|
||||
return node as Token<TKind>;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1750,10 +1751,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
: node;
|
||||
}
|
||||
|
||||
function finishUpdatePropertySignature(updated: Mutable<PropertySignature>, original: PropertySignature) {
|
||||
function finishUpdatePropertySignature(updated: PropertySignature, original: PropertySignature) {
|
||||
if (updated !== original) {
|
||||
// copy children used only for error reporting
|
||||
updated.initializer = original.initializer;
|
||||
(updated as Mutable<PropertySignature>).initializer = original.initializer;
|
||||
}
|
||||
return update(updated, original);
|
||||
}
|
||||
|
@ -1966,10 +1967,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
: node;
|
||||
}
|
||||
|
||||
function finishUpdateClassStaticBlockDeclaration(updated: Mutable<ClassStaticBlockDeclaration>, original: ClassStaticBlockDeclaration) {
|
||||
function finishUpdateClassStaticBlockDeclaration(updated: ClassStaticBlockDeclaration, original: ClassStaticBlockDeclaration) {
|
||||
if (updated !== original) {
|
||||
// copy children used only for error reporting
|
||||
updated.modifiers = original.modifiers;
|
||||
(updated as Mutable<ClassStaticBlockDeclaration>).modifiers = original.modifiers;
|
||||
}
|
||||
return update(updated, original);
|
||||
}
|
||||
|
@ -2343,10 +2344,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
: node;
|
||||
}
|
||||
|
||||
function finishUpdateFunctionTypeNode(updated: Mutable<FunctionTypeNode>, original: FunctionTypeNode) {
|
||||
function finishUpdateFunctionTypeNode(updated: FunctionTypeNode, original: FunctionTypeNode) {
|
||||
if (updated !== original) {
|
||||
// copy children used only for error reporting
|
||||
updated.modifiers = original.modifiers;
|
||||
(updated as Mutable<FunctionTypeNode>).modifiers = original.modifiers;
|
||||
}
|
||||
return finishUpdateBaseSignatureDeclaration(updated, original);
|
||||
}
|
||||
|
@ -3027,7 +3028,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
}
|
||||
|
||||
// @api
|
||||
function createCallExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined) {
|
||||
function createCallExpression(expression: Expression, typeArguments: readonly TypeNode[] | undefined, argumentsArray: readonly Expression[] | undefined): CallExpression {
|
||||
const node = createBaseCallExpression(
|
||||
parenthesizerRules().parenthesizeLeftSideOfAccess(expression, /*optionalChain*/ false),
|
||||
/*questionDotToken*/ undefined,
|
||||
|
@ -3408,7 +3409,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
}
|
||||
|
||||
// @api
|
||||
function createBinaryExpression(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression) {
|
||||
function createBinaryExpression(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression): BinaryExpression {
|
||||
const node = createBaseDeclaration<BinaryExpression>(SyntaxKind.BinaryExpression);
|
||||
const operatorToken = asToken(operator);
|
||||
const operatorKind = operatorToken.kind;
|
||||
|
@ -3567,7 +3568,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
}
|
||||
|
||||
// @api
|
||||
function createTemplateLiteralLikeNode(kind: TemplateLiteralToken["kind"], text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined) {
|
||||
function createTemplateLiteralLikeNode(kind: TemplateLiteralToken["kind"], text: string, rawText: string | undefined, templateFlags: TokenFlags | undefined): TemplateLiteralLikeNode {
|
||||
if (kind === SyntaxKind.NoSubstitutionTemplateLiteral) {
|
||||
return createTemplateLiteralLikeDeclaration(kind, text, rawText, templateFlags);
|
||||
}
|
||||
|
@ -5474,7 +5475,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
// createJSDocThisTag
|
||||
// createJSDocEnumTag
|
||||
// createJSDocSatisfiesTag
|
||||
function createJSDocTypeLikeTagWorker<T extends JSDocTag & { typeExpression?: JSDocTypeExpression; }>(kind: T["kind"], tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string | NodeArray<JSDocComment>) {
|
||||
function createJSDocTypeLikeTagWorker<T extends JSDocTag & { readonly typeExpression?: JSDocTypeExpression; }>(kind: T["kind"], tagName: Identifier | undefined, typeExpression?: JSDocTypeExpression, comment?: string | NodeArray<JSDocComment>) {
|
||||
const node = createBaseJSDocTag<T>(kind, tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), comment);
|
||||
node.typeExpression = typeExpression;
|
||||
return node;
|
||||
|
@ -5486,7 +5487,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
// updateJSDocThisTag
|
||||
// updateJSDocEnumTag
|
||||
// updateJSDocSatisfiesTag
|
||||
function updateJSDocTypeLikeTagWorker<T extends JSDocTag & { typeExpression?: JSDocTypeExpression; }>(kind: T["kind"], node: T, tagName: Identifier = getDefaultTagName(node), typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray<JSDocComment> | undefined) {
|
||||
function updateJSDocTypeLikeTagWorker<T extends JSDocTag & { readonly typeExpression?: JSDocTypeExpression; }>(kind: T["kind"], node: T, tagName: Identifier = getDefaultTagName(node), typeExpression: JSDocTypeExpression | undefined, comment: string | NodeArray<JSDocComment> | undefined) {
|
||||
return node.tagName !== tagName
|
||||
|| node.typeExpression !== typeExpression
|
||||
|| node.comment !== comment
|
||||
|
@ -6354,7 +6355,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
return node;
|
||||
}
|
||||
if (isSourceFile(node)) {
|
||||
return cloneSourceFile(node) as T & SourceFile;
|
||||
return cloneSourceFile(node) as SourceFile as T & SourceFile;
|
||||
}
|
||||
if (isGeneratedIdentifier(node)) {
|
||||
return cloneGeneratedIdentifier(node) as T & GeneratedIdentifier;
|
||||
|
@ -7154,7 +7155,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
|
|||
return variableDeclaration;
|
||||
}
|
||||
|
||||
function update<T extends Node>(updated: Mutable<T>, original: T): T {
|
||||
function update<T extends Node>(updated: T, original: T): T {
|
||||
if (updated !== original) {
|
||||
setOriginal(updated, original);
|
||||
setTextRange(updated, original);
|
||||
|
@ -7511,7 +7512,7 @@ function mergeEmitNode(sourceEmitNode: EmitNode, destEmitNode: EmitNode | undefi
|
|||
return destEmitNode;
|
||||
}
|
||||
|
||||
function mergeTokenSourceMapRanges(sourceRanges: (TextRange | undefined)[], destRanges: (TextRange | undefined)[]) {
|
||||
function mergeTokenSourceMapRanges(sourceRanges: (ReadonlyTextRange | undefined)[], destRanges: (ReadonlyTextRange | undefined)[]) {
|
||||
if (!destRanges) destRanges = [];
|
||||
for (const key in sourceRanges) {
|
||||
destRanges[key] = sourceRanges[key];
|
||||
|
|
|
@ -151,6 +151,7 @@ import {
|
|||
pushIfUnique,
|
||||
QuestionToken,
|
||||
ReadonlyKeyword,
|
||||
ReadonlyTextRange,
|
||||
RelationalOperator,
|
||||
RelationalOperatorOrHigher,
|
||||
SetAccessorDeclaration,
|
||||
|
@ -182,7 +183,7 @@ export function createEmptyExports(factory: NodeFactory) {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function createMemberAccessForPropertyName(factory: NodeFactory, target: Expression, memberName: PropertyName, location?: TextRange): MemberExpression {
|
||||
export function createMemberAccessForPropertyName(factory: NodeFactory, target: Expression, memberName: PropertyName, location?: ReadonlyTextRange): MemberExpression {
|
||||
if (isComputedPropertyName(memberName)) {
|
||||
return setTextRange(factory.createElementAccessExpression(target, memberName.expression), location);
|
||||
}
|
||||
|
@ -241,7 +242,7 @@ function createJsxFragmentFactoryExpression(factory: NodeFactory, jsxFragmentFac
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function createExpressionForJsxElement(factory: NodeFactory, callee: Expression, tagName: Expression, props: Expression | undefined, children: readonly Expression[] | undefined, location: TextRange): LeftHandSideExpression {
|
||||
export function createExpressionForJsxElement(factory: NodeFactory, callee: Expression, tagName: Expression, props: Expression | undefined, children: readonly Expression[] | undefined, location: ReadonlyTextRange): LeftHandSideExpression {
|
||||
const argumentsList = [tagName];
|
||||
if (props) {
|
||||
argumentsList.push(props);
|
||||
|
@ -274,7 +275,7 @@ export function createExpressionForJsxElement(factory: NodeFactory, callee: Expr
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function createExpressionForJsxFragment(factory: NodeFactory, jsxFactoryEntity: EntityName | undefined, jsxFragmentFactoryEntity: EntityName | undefined, reactNamespace: string, children: readonly Expression[], parentElement: JsxOpeningFragment, location: TextRange): LeftHandSideExpression {
|
||||
export function createExpressionForJsxFragment(factory: NodeFactory, jsxFactoryEntity: EntityName | undefined, jsxFragmentFactoryEntity: EntityName | undefined, reactNamespace: string, children: readonly Expression[], parentElement: JsxOpeningFragment, location: ReadonlyTextRange): LeftHandSideExpression {
|
||||
const tagName = createJsxFragmentFactoryExpression(factory, jsxFragmentFactoryEntity, reactNamespace, parentElement);
|
||||
const argumentsList = [tagName, factory.createNull()];
|
||||
|
||||
|
|
|
@ -2,12 +2,13 @@ import {
|
|||
HasDecorators,
|
||||
HasModifiers,
|
||||
Node,
|
||||
ReadonlyTextRange,
|
||||
setTextRangePosEnd,
|
||||
SyntaxKind,
|
||||
TextRange,
|
||||
} from "../_namespaces/ts.js";
|
||||
|
||||
export function setTextRange<T extends TextRange>(range: T, location: TextRange | undefined): T {
|
||||
export function setTextRange<T extends ReadonlyTextRange>(range: T, location: ReadonlyTextRange | undefined): T {
|
||||
return location ? setTextRangePosEnd(range, location.pos, location.end) : range;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ export interface ModuleSpecifierPreferences {
|
|||
export function getModuleSpecifierPreferences(
|
||||
{ importModuleSpecifierPreference, importModuleSpecifierEnding }: UserPreferences,
|
||||
compilerOptions: CompilerOptions,
|
||||
importingSourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat">,
|
||||
importingSourceFile: Readonly<Pick<SourceFile, "fileName" | "impliedNodeFormat">>,
|
||||
oldImportSpecifier?: string,
|
||||
): ModuleSpecifierPreferences {
|
||||
const filePreferredEnding = getPreferredEnding();
|
||||
|
@ -389,7 +389,7 @@ export function getModuleSpecifiersWithCacheInfo(
|
|||
|
||||
/** @internal */
|
||||
export function getLocalModuleSpecifierBetweenFileNames(
|
||||
importingFile: Pick<SourceFile, "fileName" | "impliedNodeFormat">,
|
||||
importingFile: Readonly<Pick<SourceFile, "fileName" | "impliedNodeFormat">>,
|
||||
targetFileName: string,
|
||||
compilerOptions: CompilerOptions,
|
||||
host: ModuleSpecifierResolutionHost,
|
||||
|
|
|
@ -319,6 +319,7 @@ import {
|
|||
QuestionToken,
|
||||
ReadonlyKeyword,
|
||||
ReadonlyPragmaMap,
|
||||
ReadonlyTextRange,
|
||||
ResolutionMode,
|
||||
RestTypeNode,
|
||||
ReturnStatement,
|
||||
|
@ -2158,7 +2159,7 @@ namespace Parser {
|
|||
return parseErrorAtPosition(start, end - start, message, ...args);
|
||||
}
|
||||
|
||||
function parseErrorAtRange(range: TextRange, message: DiagnosticMessage, ...args: DiagnosticArguments): void {
|
||||
function parseErrorAtRange(range: ReadonlyTextRange, message: DiagnosticMessage, ...args: DiagnosticArguments): void {
|
||||
parseErrorAt(range.pos, range.end, message, ...args);
|
||||
}
|
||||
|
||||
|
@ -6704,7 +6705,7 @@ namespace Parser {
|
|||
if (isShorthandPropertyAssignment) {
|
||||
const equalsToken = parseOptionalToken(SyntaxKind.EqualsToken);
|
||||
const objectAssignmentInitializer = equalsToken ? allowInAnd(() => parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true)) : undefined;
|
||||
node = factory.createShorthandPropertyAssignment(name as Identifier, objectAssignmentInitializer);
|
||||
node = factory.createShorthandPropertyAssignment(name as Identifier, objectAssignmentInitializer) as Mutable<ShorthandPropertyAssignment>;
|
||||
// Save equals token for error reporting.
|
||||
// TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful.
|
||||
node.equalsToken = equalsToken;
|
||||
|
@ -6712,7 +6713,7 @@ namespace Parser {
|
|||
else {
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
const initializer = allowInAnd(() => parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true));
|
||||
node = factory.createPropertyAssignment(name, initializer);
|
||||
node = factory.createPropertyAssignment(name, initializer) as Mutable<PropertyAssignment>;
|
||||
}
|
||||
// Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker
|
||||
node.modifiers = modifiers;
|
||||
|
|
|
@ -13,7 +13,7 @@ export interface PerformanceHooks {
|
|||
/** @internal */
|
||||
export interface PerformanceTime {
|
||||
now(): number;
|
||||
timeOrigin: number;
|
||||
readonly timeOrigin: number;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
|
|
@ -183,7 +183,7 @@ export interface CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations e
|
|||
/** @internal */
|
||||
export interface ResolutionCacheHost extends MinimalResolutionCacheHost {
|
||||
toPath(fileName: string): Path;
|
||||
getCanonicalFileName: GetCanonicalFileName;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
getCompilationSettings(): CompilerOptions;
|
||||
preferNonRecursiveWatch: boolean | undefined;
|
||||
watchDirectoryOfFailedLookupLocation(directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags): FileWatcher;
|
||||
|
@ -193,7 +193,7 @@ export interface ResolutionCacheHost extends MinimalResolutionCacheHost {
|
|||
onChangedAutomaticTypeDirectiveNames(): void;
|
||||
scheduleInvalidateResolutionsOfFailedLookupLocations(): void;
|
||||
getCachedDirectoryStructureHost(): CachedDirectoryStructureHost | undefined;
|
||||
projectName?: string;
|
||||
readonly projectName?: string;
|
||||
getGlobalCache?(): string | undefined;
|
||||
globalCacheResolutionModuleName?(externalModuleName: string): string;
|
||||
writeLog(s: string): void;
|
||||
|
|
|
@ -134,7 +134,7 @@ function setCustomPollingValues(system: System) {
|
|||
if (!system.getEnvironmentVariable) {
|
||||
return;
|
||||
}
|
||||
const pollingIntervalChanged = setCustomLevels("TSC_WATCH_POLLINGINTERVAL", PollingInterval);
|
||||
const pollingIntervalChanged = setCustomLevels("TSC_WATCH_POLLINGINTERVAL", PollingInterval as Levels); // Could modify enum which doesn't seen right
|
||||
pollingChunkSize = getCustomPollingBasedLevels("TSC_WATCH_POLLINGCHUNKSIZE", defaultChunkLevels) || pollingChunkSize;
|
||||
unchangedPollThresholds = getCustomPollingBasedLevels("TSC_WATCH_UNCHANGEDPOLLTHRESHOLDS", defaultChunkLevels) || unchangedPollThresholds;
|
||||
|
||||
|
@ -1393,9 +1393,9 @@ export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "
|
|||
|
||||
// TODO: GH#18217 Methods on System are often used as if they are certainly defined
|
||||
export interface System {
|
||||
args: string[];
|
||||
newLine: string;
|
||||
useCaseSensitiveFileNames: boolean;
|
||||
readonly args: string[];
|
||||
readonly newLine: string;
|
||||
readonly useCaseSensitiveFileNames: boolean;
|
||||
write(s: string): void;
|
||||
writeOutputIsTTY?(): boolean;
|
||||
getWidthOfTerminal?(): number;
|
||||
|
|
|
@ -51,6 +51,7 @@ import {
|
|||
ObjectBindingOrAssignmentPattern,
|
||||
ParameterDeclaration,
|
||||
PropertyName,
|
||||
ReadonlyTextRange,
|
||||
setTextRange,
|
||||
some,
|
||||
TextRange,
|
||||
|
@ -69,7 +70,7 @@ interface FlattenContext {
|
|||
hoistTempVariables: boolean;
|
||||
hasTransformedPriorElement?: boolean; // indicates whether we've transformed a prior declaration
|
||||
emitExpression: (value: Expression) => void;
|
||||
emitBindingOrAssignment: (target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange, original: Node | undefined) => void;
|
||||
emitBindingOrAssignment: (target: BindingOrAssignmentElementTarget, value: Expression, location: ReadonlyTextRange, original: Node | undefined) => void;
|
||||
createArrayBindingOrAssignmentPattern: (elements: BindingOrAssignmentElement[]) => ArrayBindingOrAssignmentPattern;
|
||||
createObjectBindingOrAssignmentPattern: (elements: BindingOrAssignmentElement[]) => ObjectBindingOrAssignmentPattern;
|
||||
createArrayBindingOrAssignmentElement: (node: Identifier) => BindingOrAssignmentElement;
|
||||
|
@ -101,9 +102,9 @@ export function flattenDestructuringAssignment(
|
|||
context: TransformationContext,
|
||||
level: FlattenLevel,
|
||||
needsValue?: boolean,
|
||||
createAssignmentCallback?: (name: Identifier, value: Expression, location?: TextRange) => Expression,
|
||||
createAssignmentCallback?: (name: Identifier, value: Expression, location?: ReadonlyTextRange) => Expression,
|
||||
): Expression {
|
||||
let location: TextRange = node;
|
||||
let location: ReadonlyTextRange = node;
|
||||
let value: Expression | undefined;
|
||||
if (isDestructuringAssignment(node)) {
|
||||
value = node.right;
|
||||
|
@ -180,7 +181,7 @@ export function flattenDestructuringAssignment(
|
|||
expressions = append(expressions, expression);
|
||||
}
|
||||
|
||||
function emitBindingOrAssignment(target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange, original: Node | undefined) {
|
||||
function emitBindingOrAssignment(target: BindingOrAssignmentElementTarget, value: Expression, location: ReadonlyTextRange, original: Node | undefined) {
|
||||
Debug.assertNode(target, createAssignmentCallback ? isIdentifier : isExpression);
|
||||
const expression = createAssignmentCallback
|
||||
? createAssignmentCallback(target as Identifier, value, location)
|
||||
|
@ -250,7 +251,7 @@ export function flattenDestructuringBinding(
|
|||
skipInitializer?: boolean,
|
||||
): VariableDeclaration[] {
|
||||
let pendingExpressions: Expression[] | undefined;
|
||||
const pendingDeclarations: { pendingExpressions?: Expression[]; name: BindingName; value: Expression; location?: TextRange; original?: Node; }[] = [];
|
||||
const pendingDeclarations: { pendingExpressions?: Expression[]; name: BindingName; value: Expression; location?: ReadonlyTextRange; original?: Node; }[] = [];
|
||||
const declarations: VariableDeclaration[] = [];
|
||||
const flattenContext: FlattenContext = {
|
||||
context,
|
||||
|
@ -314,7 +315,7 @@ export function flattenDestructuringBinding(
|
|||
pendingExpressions = append(pendingExpressions, value);
|
||||
}
|
||||
|
||||
function emitBindingOrAssignment(target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange | undefined, original: Node | undefined) {
|
||||
function emitBindingOrAssignment(target: BindingOrAssignmentElementTarget, value: Expression, location: ReadonlyTextRange | undefined, original: Node | undefined) {
|
||||
Debug.assertNode(target, isBindingName);
|
||||
if (pendingExpressions) {
|
||||
value = context.factory.inlineExpressions(append(pendingExpressions, value));
|
||||
|
@ -338,7 +339,7 @@ function flattenBindingOrAssignmentElement(
|
|||
flattenContext: FlattenContext,
|
||||
element: BindingOrAssignmentElement,
|
||||
value: Expression | undefined,
|
||||
location: TextRange,
|
||||
location: ReadonlyTextRange,
|
||||
skipInitializer?: boolean,
|
||||
) {
|
||||
const bindingTarget = getTargetOfBindingOrAssignmentElement(element)!; // TODO: GH#18217
|
||||
|
@ -382,7 +383,7 @@ function flattenBindingOrAssignmentElement(
|
|||
* @param value The current RHS value to assign to the element.
|
||||
* @param location The location to use for source maps and comments.
|
||||
*/
|
||||
function flattenObjectBindingOrAssignmentPattern(flattenContext: FlattenContext, parent: BindingOrAssignmentElement, pattern: ObjectBindingOrAssignmentPattern, value: Expression, location: TextRange) {
|
||||
function flattenObjectBindingOrAssignmentPattern(flattenContext: FlattenContext, parent: BindingOrAssignmentElement, pattern: ObjectBindingOrAssignmentPattern, value: Expression, location: ReadonlyTextRange) {
|
||||
const elements = getElementsOfBindingOrAssignmentPattern(pattern);
|
||||
const numElements = elements.length;
|
||||
if (numElements !== 1) {
|
||||
|
@ -442,7 +443,7 @@ function flattenObjectBindingOrAssignmentPattern(flattenContext: FlattenContext,
|
|||
* @param value The current RHS value to assign to the element.
|
||||
* @param location The location to use for source maps and comments.
|
||||
*/
|
||||
function flattenArrayBindingOrAssignmentPattern(flattenContext: FlattenContext, parent: BindingOrAssignmentElement, pattern: ArrayBindingOrAssignmentPattern, value: Expression, location: TextRange) {
|
||||
function flattenArrayBindingOrAssignmentPattern(flattenContext: FlattenContext, parent: BindingOrAssignmentElement, pattern: ArrayBindingOrAssignmentPattern, value: Expression, location: ReadonlyTextRange) {
|
||||
const elements = getElementsOfBindingOrAssignmentPattern(pattern);
|
||||
const numElements = elements.length;
|
||||
if (flattenContext.level < FlattenLevel.ObjectRest && flattenContext.downlevelIteration) {
|
||||
|
@ -537,7 +538,7 @@ function isSimpleBindingOrAssignmentElement(element: BindingOrAssignmentElement)
|
|||
* @param defaultValue The default value to use if `value` is `undefined` at runtime.
|
||||
* @param location The location to use for source maps and comments.
|
||||
*/
|
||||
function createDefaultValueCheck(flattenContext: FlattenContext, value: Expression, defaultValue: Expression, location: TextRange): Expression {
|
||||
function createDefaultValueCheck(flattenContext: FlattenContext, value: Expression, defaultValue: Expression, location: ReadonlyTextRange): Expression {
|
||||
value = ensureIdentifier(flattenContext, value, /*reuseIdentifierExpressions*/ true, location);
|
||||
return flattenContext.context.factory.createConditionalExpression(flattenContext.context.factory.createTypeCheck(value, "undefined"), /*questionToken*/ undefined, defaultValue, /*colonToken*/ undefined, value);
|
||||
}
|
||||
|
@ -579,7 +580,7 @@ function createDestructuringPropertyAccess(flattenContext: FlattenContext, value
|
|||
* false if it is necessary to always emit an identifier.
|
||||
* @param location The location to use for source maps and comments.
|
||||
*/
|
||||
function ensureIdentifier(flattenContext: FlattenContext, value: Expression, reuseIdentifierExpressions: boolean, location: TextRange) {
|
||||
function ensureIdentifier(flattenContext: FlattenContext, value: Expression, reuseIdentifierExpressions: boolean, location: ReadonlyTextRange) {
|
||||
if (isIdentifier(value) && reuseIdentifierExpressions) {
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -168,6 +168,7 @@ import {
|
|||
PropertyAssignment,
|
||||
PropertyDeclaration,
|
||||
rangeEndIsOnSameLineAsRangeStart,
|
||||
ReadonlyTextRange,
|
||||
ReturnStatement,
|
||||
SemicolonClassElement,
|
||||
setCommentRange,
|
||||
|
@ -2508,7 +2509,7 @@ export function transformES2015(context: TransformationContext): (x: SourceFile
|
|||
* @param location The source-map location for the new FunctionExpression.
|
||||
* @param name The name of the new FunctionExpression.
|
||||
*/
|
||||
function transformFunctionLikeToExpression(node: FunctionLikeDeclaration, location: TextRange | undefined, name: Identifier | undefined, container: Node | undefined): FunctionExpression {
|
||||
function transformFunctionLikeToExpression(node: FunctionLikeDeclaration, location: ReadonlyTextRange | undefined, name: Identifier | undefined, container: Node | undefined): FunctionExpression {
|
||||
const savedConvertedLoopState = convertedLoopState;
|
||||
convertedLoopState = undefined;
|
||||
const ancestorFacts = container && isClassLike(container) && !isStatic(node)
|
||||
|
@ -2547,8 +2548,8 @@ export function transformES2015(context: TransformationContext): (x: SourceFile
|
|||
function transformFunctionBody(node: FunctionLikeDeclaration) {
|
||||
let multiLine = false; // indicates whether the block *must* be emitted as multiple lines
|
||||
let singleLine = false; // indicates whether the block *may* be emitted as a single line
|
||||
let statementsLocation: TextRange;
|
||||
let closeBraceLocation: TextRange | undefined;
|
||||
let statementsLocation: ReadonlyTextRange;
|
||||
let closeBraceLocation: ReadonlyTextRange | undefined;
|
||||
|
||||
const prologue: Statement[] = [];
|
||||
const statements: Statement[] = [];
|
||||
|
|
|
@ -73,6 +73,7 @@ import {
|
|||
ParameterDeclaration,
|
||||
PropertyAccessExpression,
|
||||
PropertyAssignment,
|
||||
ReadonlyTextRange,
|
||||
ScriptTarget,
|
||||
SetAccessorDeclaration,
|
||||
setEmitFlags,
|
||||
|
@ -1023,7 +1024,7 @@ export function transformES2017(context: TransformationContext): (x: SourceFile
|
|||
|| kind === SyntaxKind.SetAccessor;
|
||||
}
|
||||
|
||||
function createSuperElementAccessInAsyncMethod(argumentExpression: Expression, location: TextRange): LeftHandSideExpression {
|
||||
function createSuperElementAccessInAsyncMethod(argumentExpression: Expression, location: ReadonlyTextRange): LeftHandSideExpression {
|
||||
if (enclosingSuperContainerFlags & NodeCheckFlags.MethodWithSuperPropertyAssignmentInAsync) {
|
||||
return setTextRange(
|
||||
factory.createPropertyAccessExpression(
|
||||
|
|
|
@ -81,6 +81,7 @@ import {
|
|||
ProcessLevel,
|
||||
processTaggedTemplateExpression,
|
||||
PropertyAccessExpression,
|
||||
ReadonlyTextRange,
|
||||
ReturnStatement,
|
||||
ScriptTarget,
|
||||
SetAccessorDeclaration,
|
||||
|
@ -743,8 +744,8 @@ export function transformES2018(context: TransformationContext): (x: SourceFile
|
|||
function transformForOfStatementWithObjectRest(node: ForOfStatement) {
|
||||
const initializerWithoutParens = skipParentheses(node.initializer) as ForInitializer;
|
||||
if (isVariableDeclarationList(initializerWithoutParens) || isAssignmentPattern(initializerWithoutParens)) {
|
||||
let bodyLocation: TextRange | undefined;
|
||||
let statementsLocation: TextRange | undefined;
|
||||
let bodyLocation: ReadonlyTextRange | undefined;
|
||||
let statementsLocation: ReadonlyTextRange | undefined;
|
||||
const temp = factory.createTempVariable(/*recordTempVariable*/ undefined);
|
||||
const statements: Statement[] = [createForOfBindingStatement(factory, initializerWithoutParens, temp)];
|
||||
if (isBlock(node.statement)) {
|
||||
|
@ -796,8 +797,8 @@ export function transformES2018(context: TransformationContext): (x: SourceFile
|
|||
const binding = createForOfBindingStatement(factory, node.initializer, value);
|
||||
statements.push(visitNode(binding, visitor, isStatement));
|
||||
|
||||
let bodyLocation: TextRange | undefined;
|
||||
let statementsLocation: TextRange | undefined;
|
||||
let bodyLocation: ReadonlyTextRange | undefined;
|
||||
let statementsLocation: ReadonlyTextRange | undefined;
|
||||
const statement = visitIterationBody(node.statement, visitor, context);
|
||||
if (isBlock(statement)) {
|
||||
addRange(statements, statement.statements);
|
||||
|
@ -1457,7 +1458,7 @@ export function transformES2018(context: TransformationContext): (x: SourceFile
|
|||
|| kind === SyntaxKind.SetAccessor;
|
||||
}
|
||||
|
||||
function createSuperElementAccessInAsyncMethod(argumentExpression: Expression, location: TextRange): LeftHandSideExpression {
|
||||
function createSuperElementAccessInAsyncMethod(argumentExpression: Expression, location: ReadonlyTextRange): LeftHandSideExpression {
|
||||
if (enclosingSuperContainerFlags & NodeCheckFlags.MethodWithSuperPropertyAssignmentInAsync) {
|
||||
return setTextRange(
|
||||
factory.createPropertyAccessExpression(
|
||||
|
|
|
@ -65,6 +65,7 @@ import {
|
|||
ObjectLiteralElementLike,
|
||||
ObjectLiteralExpression,
|
||||
PropertyAccessExpression,
|
||||
ReadonlyTextRange,
|
||||
reduceLeft,
|
||||
ReturnStatement,
|
||||
setCommentRange,
|
||||
|
@ -370,7 +371,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
// allocating objects to store the same information to avoid GC overhead.
|
||||
//
|
||||
let labelOffsets: number[] | undefined; // The operation offset at which the label is defined.
|
||||
let labelExpressions: Mutable<LiteralExpression>[][] | undefined; // The NumericLiteral nodes bound to each label.
|
||||
let labelExpressions: LiteralExpression[][] | undefined; // The NumericLiteral nodes bound to each label.
|
||||
let nextLabelId = 1; // The next label id to use.
|
||||
|
||||
// Operations store information about generated code for the function body. This
|
||||
|
@ -380,7 +381,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
//
|
||||
let operations: OpCode[] | undefined; // The operation to perform.
|
||||
let operationArguments: (OperationArguments | undefined)[] | undefined; // The arguments to the operation.
|
||||
let operationLocations: (TextRange | undefined)[] | undefined; // The source map location for the operation.
|
||||
let operationLocations: (ReadonlyTextRange | undefined)[] | undefined; // The source map location for the operation.
|
||||
|
||||
let state: Identifier; // The name of the state object used by the generator at runtime.
|
||||
|
||||
|
@ -1070,7 +1071,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param elements The elements to visit.
|
||||
* @param multiLine Whether array literals created should be emitted on multiple lines.
|
||||
*/
|
||||
function visitElements(elements: NodeArray<Expression>, leadingElement?: Expression, location?: TextRange, multiLine?: boolean) {
|
||||
function visitElements(elements: NodeArray<Expression>, leadingElement?: Expression, location?: ReadonlyTextRange, multiLine?: boolean) {
|
||||
// [source]
|
||||
// ar = [1, yield, 2];
|
||||
//
|
||||
|
@ -2553,7 +2554,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param label A label.
|
||||
* @param location An optional source map location for the statement.
|
||||
*/
|
||||
function createInlineBreak(label: Label, location?: TextRange): ReturnStatement {
|
||||
function createInlineBreak(label: Label, location?: ReadonlyTextRange): ReturnStatement {
|
||||
Debug.assertLessThan(0, label, "Invalid label");
|
||||
return setTextRange(
|
||||
factory.createReturnStatement(
|
||||
|
@ -2572,7 +2573,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression The expression for the return statement.
|
||||
* @param location An optional source map location for the statement.
|
||||
*/
|
||||
function createInlineReturn(expression?: Expression, location?: TextRange): ReturnStatement {
|
||||
function createInlineReturn(expression?: Expression, location?: ReadonlyTextRange): ReturnStatement {
|
||||
return setTextRange(
|
||||
factory.createReturnStatement(
|
||||
factory.createArrayLiteralExpression(
|
||||
|
@ -2588,7 +2589,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
/**
|
||||
* Creates an expression that can be used to resume from a Yield operation.
|
||||
*/
|
||||
function createGeneratorResume(location?: TextRange): LeftHandSideExpression {
|
||||
function createGeneratorResume(location?: ReadonlyTextRange): LeftHandSideExpression {
|
||||
return setTextRange(
|
||||
factory.createCallExpression(
|
||||
factory.createPropertyAccessExpression(state, "sent"),
|
||||
|
@ -2627,7 +2628,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param right The right-hand side of the assignment.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitAssignment(left: Expression, right: Expression, location?: TextRange): void {
|
||||
function emitAssignment(left: Expression, right: Expression, location?: ReadonlyTextRange): void {
|
||||
emitWorker(OpCode.Assign, [left, right], location);
|
||||
}
|
||||
|
||||
|
@ -2637,7 +2638,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param label A label.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitBreak(label: Label, location?: TextRange): void {
|
||||
function emitBreak(label: Label, location?: ReadonlyTextRange): void {
|
||||
emitWorker(OpCode.Break, [label], location);
|
||||
}
|
||||
|
||||
|
@ -2649,7 +2650,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param condition The condition.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitBreakWhenTrue(label: Label, condition: Expression, location?: TextRange): void {
|
||||
function emitBreakWhenTrue(label: Label, condition: Expression, location?: ReadonlyTextRange): void {
|
||||
emitWorker(OpCode.BreakWhenTrue, [label, condition], location);
|
||||
}
|
||||
|
||||
|
@ -2661,7 +2662,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param condition The condition.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitBreakWhenFalse(label: Label, condition: Expression, location?: TextRange): void {
|
||||
function emitBreakWhenFalse(label: Label, condition: Expression, location?: ReadonlyTextRange): void {
|
||||
emitWorker(OpCode.BreakWhenFalse, [label, condition], location);
|
||||
}
|
||||
|
||||
|
@ -2671,7 +2672,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression An optional value for the yield operation.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitYieldStar(expression?: Expression, location?: TextRange): void {
|
||||
function emitYieldStar(expression?: Expression, location?: ReadonlyTextRange): void {
|
||||
emitWorker(OpCode.YieldStar, [expression], location);
|
||||
}
|
||||
|
||||
|
@ -2681,7 +2682,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression An optional value for the yield operation.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitYield(expression?: Expression, location?: TextRange): void {
|
||||
function emitYield(expression?: Expression, location?: ReadonlyTextRange): void {
|
||||
emitWorker(OpCode.Yield, [expression], location);
|
||||
}
|
||||
|
||||
|
@ -2691,7 +2692,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression An optional value for the operation.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitReturn(expression?: Expression, location?: TextRange): void {
|
||||
function emitReturn(expression?: Expression, location?: ReadonlyTextRange): void {
|
||||
emitWorker(OpCode.Return, [expression], location);
|
||||
}
|
||||
|
||||
|
@ -2701,7 +2702,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression A value for the operation.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitThrow(expression: Expression, location?: TextRange): void {
|
||||
function emitThrow(expression: Expression, location?: ReadonlyTextRange): void {
|
||||
emitWorker(OpCode.Throw, [expression], location);
|
||||
}
|
||||
|
||||
|
@ -2718,7 +2719,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param code The OpCode for the operation.
|
||||
* @param args The optional arguments for the operation.
|
||||
*/
|
||||
function emitWorker(code: OpCode, args?: OperationArguments, location?: TextRange): void {
|
||||
function emitWorker(code: OpCode, args?: OperationArguments, location?: ReadonlyTextRange): void {
|
||||
if (operations === undefined) {
|
||||
operations = [];
|
||||
operationArguments = [];
|
||||
|
@ -3093,7 +3094,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param right The right-hand side of the assignment.
|
||||
* @param operationLocation The source map location for the operation.
|
||||
*/
|
||||
function writeAssign(left: Expression, right: Expression, operationLocation: TextRange | undefined): void {
|
||||
function writeAssign(left: Expression, right: Expression, operationLocation: ReadonlyTextRange | undefined): void {
|
||||
writeStatement(setTextRange(factory.createExpressionStatement(factory.createAssignment(left, right)), operationLocation));
|
||||
}
|
||||
|
||||
|
@ -3103,7 +3104,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression The value to throw.
|
||||
* @param operationLocation The source map location for the operation.
|
||||
*/
|
||||
function writeThrow(expression: Expression, operationLocation: TextRange | undefined): void {
|
||||
function writeThrow(expression: Expression, operationLocation: ReadonlyTextRange | undefined): void {
|
||||
lastOperationWasAbrupt = true;
|
||||
lastOperationWasCompletion = true;
|
||||
writeStatement(setTextRange(factory.createThrowStatement(expression), operationLocation));
|
||||
|
@ -3115,7 +3116,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression The value to return.
|
||||
* @param operationLocation The source map location for the operation.
|
||||
*/
|
||||
function writeReturn(expression: Expression | undefined, operationLocation: TextRange | undefined): void {
|
||||
function writeReturn(expression: Expression | undefined, operationLocation: ReadonlyTextRange | undefined): void {
|
||||
lastOperationWasAbrupt = true;
|
||||
lastOperationWasCompletion = true;
|
||||
writeStatement(
|
||||
|
@ -3141,7 +3142,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param label The label for the Break.
|
||||
* @param operationLocation The source map location for the operation.
|
||||
*/
|
||||
function writeBreak(label: Label, operationLocation: TextRange | undefined): void {
|
||||
function writeBreak(label: Label, operationLocation: ReadonlyTextRange | undefined): void {
|
||||
lastOperationWasAbrupt = true;
|
||||
writeStatement(
|
||||
setEmitFlags(
|
||||
|
@ -3166,7 +3167,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param condition The condition for the Break.
|
||||
* @param operationLocation The source map location for the operation.
|
||||
*/
|
||||
function writeBreakWhenTrue(label: Label, condition: Expression, operationLocation: TextRange | undefined): void {
|
||||
function writeBreakWhenTrue(label: Label, condition: Expression, operationLocation: ReadonlyTextRange | undefined): void {
|
||||
writeStatement(
|
||||
setEmitFlags(
|
||||
factory.createIfStatement(
|
||||
|
@ -3196,7 +3197,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param condition The condition for the Break.
|
||||
* @param operationLocation The source map location for the operation.
|
||||
*/
|
||||
function writeBreakWhenFalse(label: Label, condition: Expression, operationLocation: TextRange | undefined): void {
|
||||
function writeBreakWhenFalse(label: Label, condition: Expression, operationLocation: ReadonlyTextRange | undefined): void {
|
||||
writeStatement(
|
||||
setEmitFlags(
|
||||
factory.createIfStatement(
|
||||
|
@ -3225,7 +3226,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression The expression to yield.
|
||||
* @param operationLocation The source map location for the operation.
|
||||
*/
|
||||
function writeYield(expression: Expression, operationLocation: TextRange | undefined): void {
|
||||
function writeYield(expression: Expression, operationLocation: ReadonlyTextRange | undefined): void {
|
||||
lastOperationWasAbrupt = true;
|
||||
writeStatement(
|
||||
setEmitFlags(
|
||||
|
@ -3250,7 +3251,7 @@ export function transformGenerators(context: TransformationContext): (x: SourceF
|
|||
* @param expression The expression to yield.
|
||||
* @param operationLocation The source map location for the operation.
|
||||
*/
|
||||
function writeYieldStar(expression: Expression, operationLocation: TextRange | undefined): void {
|
||||
function writeYieldStar(expression: Expression, operationLocation: ReadonlyTextRange | undefined): void {
|
||||
lastOperationWasAbrupt = true;
|
||||
writeStatement(
|
||||
setEmitFlags(
|
||||
|
|
|
@ -64,6 +64,7 @@ import {
|
|||
ObjectLiteralElementLike,
|
||||
ObjectLiteralExpression,
|
||||
PropertyAssignment,
|
||||
ReadonlyTextRange,
|
||||
sameMap,
|
||||
ScriptTarget,
|
||||
setIdentifierGeneratedImportReference,
|
||||
|
@ -311,7 +312,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B
|
|||
return length(result) ? factory.createPropertyAssignment("children", factory.createArrayLiteralExpression(result)) : undefined;
|
||||
}
|
||||
|
||||
function visitJsxOpeningLikeElementJSX(node: JsxOpeningLikeElement, children: readonly JsxChild[] | undefined, isChild: boolean, location: TextRange) {
|
||||
function visitJsxOpeningLikeElementJSX(node: JsxOpeningLikeElement, children: readonly JsxChild[] | undefined, isChild: boolean, location: ReadonlyTextRange) {
|
||||
const tagName = getTagName(node);
|
||||
const childrenProp = children && children.length ? convertJsxChildrenToChildrenPropAssignment(children) : undefined;
|
||||
const keyAttr = find(node.attributes.properties, p => !!p.name && isIdentifier(p.name) && p.name.escapedText === "key") as JsxAttribute | undefined;
|
||||
|
@ -334,7 +335,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B
|
|||
keyAttr: JsxAttribute | undefined,
|
||||
children: readonly JsxChild[],
|
||||
isChild: boolean,
|
||||
location: TextRange,
|
||||
location: ReadonlyTextRange,
|
||||
) {
|
||||
const nonWhitespaceChildren = getSemanticJsxChildren(children);
|
||||
const isStaticChildren = length(nonWhitespaceChildren) > 1 || !!(nonWhitespaceChildren[0] as JsxExpression)?.dotDotDotToken;
|
||||
|
@ -377,7 +378,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B
|
|||
return element;
|
||||
}
|
||||
|
||||
function visitJsxOpeningLikeElementCreateElement(node: JsxOpeningLikeElement, children: readonly JsxChild[] | undefined, isChild: boolean, location: TextRange) {
|
||||
function visitJsxOpeningLikeElementCreateElement(node: JsxOpeningLikeElement, children: readonly JsxChild[] | undefined, isChild: boolean, location: ReadonlyTextRange) {
|
||||
const tagName = getTagName(node);
|
||||
const attrs = node.attributes.properties;
|
||||
const objectProperties = length(attrs) ? transformJsxAttributesToObjectProps(attrs) :
|
||||
|
@ -408,7 +409,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B
|
|||
return element;
|
||||
}
|
||||
|
||||
function visitJsxOpeningFragmentJSX(_node: JsxOpeningFragment, children: readonly JsxChild[], isChild: boolean, location: TextRange) {
|
||||
function visitJsxOpeningFragmentJSX(_node: JsxOpeningFragment, children: readonly JsxChild[], isChild: boolean, location: ReadonlyTextRange) {
|
||||
let childrenProps: Expression | undefined;
|
||||
if (children && children.length) {
|
||||
const result = convertJsxChildrenToChildrenPropObject(children);
|
||||
|
@ -426,7 +427,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B
|
|||
);
|
||||
}
|
||||
|
||||
function visitJsxOpeningFragmentCreateElement(node: JsxOpeningFragment, children: readonly JsxChild[], isChild: boolean, location: TextRange) {
|
||||
function visitJsxOpeningFragmentCreateElement(node: JsxOpeningFragment, children: readonly JsxChild[], isChild: boolean, location: ReadonlyTextRange) {
|
||||
const element = createExpressionForJsxFragment(
|
||||
factory,
|
||||
context.getEmitResolver().getJsxFactoryEntity(currentSourceFile),
|
||||
|
|
|
@ -134,6 +134,7 @@ import {
|
|||
PartiallyEmittedExpression,
|
||||
PostfixUnaryExpression,
|
||||
PrefixUnaryExpression,
|
||||
ReadonlyTextRange,
|
||||
reduceLeft,
|
||||
removeAllComments,
|
||||
ScriptTarget,
|
||||
|
@ -1863,7 +1864,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
|
|||
return singleOrMany(statements);
|
||||
}
|
||||
|
||||
function createAllExportExpressions(name: Identifier, value: Expression, location?: TextRange) {
|
||||
function createAllExportExpressions(name: Identifier, value: Expression, location?: ReadonlyTextRange) {
|
||||
const exportedNames = getExports(name);
|
||||
if (exportedNames) {
|
||||
// For each additional export of the declaration, apply an export assignment.
|
||||
|
@ -2089,7 +2090,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
|
|||
* @param location The location to use for source maps and comments for the export.
|
||||
* @param allowComments Whether to allow comments on the export.
|
||||
*/
|
||||
function appendExportStatement(statements: Statement[] | undefined, seen: IdentifierNameMap<boolean>, exportName: ModuleExportName, expression: Expression, location?: TextRange, allowComments?: boolean, liveBinding?: boolean): Statement[] | undefined {
|
||||
function appendExportStatement(statements: Statement[] | undefined, seen: IdentifierNameMap<boolean>, exportName: ModuleExportName, expression: Expression, location?: ReadonlyTextRange, allowComments?: boolean, liveBinding?: boolean): Statement[] | undefined {
|
||||
if (exportName.kind !== SyntaxKind.StringLiteral) {
|
||||
if (seen.has(exportName)) {
|
||||
return statements;
|
||||
|
@ -2126,7 +2127,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
|
|||
* @param location The location to use for source maps and comments for the export.
|
||||
* @param allowComments An optional value indicating whether to emit comments for the statement.
|
||||
*/
|
||||
function createExportStatement(name: ModuleExportName, value: Expression, location?: TextRange, allowComments?: boolean, liveBinding?: boolean) {
|
||||
function createExportStatement(name: ModuleExportName, value: Expression, location?: ReadonlyTextRange, allowComments?: boolean, liveBinding?: boolean) {
|
||||
const statement = setTextRange(factory.createExpressionStatement(createExportExpression(name, value, /*location*/ undefined, liveBinding)), location);
|
||||
startOnNewLine(statement);
|
||||
if (!allowComments) {
|
||||
|
@ -2143,7 +2144,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
|
|||
* @param value The exported value.
|
||||
* @param location The location to use for source maps and comments for the export.
|
||||
*/
|
||||
function createExportExpression(name: ModuleExportName, value: Expression, location?: TextRange, liveBinding?: boolean) {
|
||||
function createExportExpression(name: ModuleExportName, value: Expression, location?: ReadonlyTextRange, liveBinding?: boolean) {
|
||||
return setTextRange(
|
||||
liveBinding ? factory.createCallExpression(
|
||||
factory.createPropertyAccessExpression(
|
||||
|
|
|
@ -104,6 +104,7 @@ import {
|
|||
PostfixUnaryExpression,
|
||||
PrefixUnaryExpression,
|
||||
PropertyAssignment,
|
||||
ReadonlyTextRange,
|
||||
setCommentRange,
|
||||
setEmitFlags,
|
||||
setTextRange,
|
||||
|
@ -971,7 +972,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
|
|||
* @param value The value of the variable's initializer.
|
||||
* @param location The source map location for the assignment.
|
||||
*/
|
||||
function createExportedVariableAssignment(name: Identifier, value: Expression, location?: TextRange) {
|
||||
function createExportedVariableAssignment(name: Identifier, value: Expression, location?: ReadonlyTextRange) {
|
||||
return createVariableAssignment(name, value, location, /*isExportedDeclaration*/ true);
|
||||
}
|
||||
|
||||
|
@ -982,7 +983,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
|
|||
* @param value The value of the variable's initializer.
|
||||
* @param location The source map location for the assignment.
|
||||
*/
|
||||
function createNonExportedVariableAssignment(name: Identifier, value: Expression, location?: TextRange) {
|
||||
function createNonExportedVariableAssignment(name: Identifier, value: Expression, location?: ReadonlyTextRange) {
|
||||
return createVariableAssignment(name, value, location, /*isExportedDeclaration*/ false);
|
||||
}
|
||||
|
||||
|
@ -994,7 +995,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
|
|||
* @param location The source map location for the assignment.
|
||||
* @param isExportedDeclaration A value indicating whether the variable is exported.
|
||||
*/
|
||||
function createVariableAssignment(name: Identifier, value: Expression, location: TextRange | undefined, isExportedDeclaration: boolean) {
|
||||
function createVariableAssignment(name: Identifier, value: Expression, location: ReadonlyTextRange | undefined, isExportedDeclaration: boolean) {
|
||||
hoistVariableDeclaration(factory.cloneNode(name));
|
||||
return isExportedDeclaration
|
||||
? createExportExpression(name, preventSubstitution(setTextRange(factory.createAssignment(name, value), location)))
|
||||
|
|
|
@ -159,6 +159,7 @@ import {
|
|||
PropertyAccessExpression,
|
||||
PropertyDeclaration,
|
||||
PropertyName,
|
||||
ReadonlyTextRange,
|
||||
removeAllComments,
|
||||
SatisfiesExpression,
|
||||
ScriptTarget,
|
||||
|
@ -2180,8 +2181,8 @@ export function transformTypeScript(context: TransformationContext) {
|
|||
const statements: Statement[] = [];
|
||||
startLexicalEnvironment();
|
||||
|
||||
let statementsLocation: TextRange | undefined;
|
||||
let blockLocation: TextRange | undefined;
|
||||
let statementsLocation: ReadonlyTextRange | undefined;
|
||||
let blockLocation: ReadonlyTextRange | undefined;
|
||||
if (node.body) {
|
||||
if (node.body.kind === SyntaxKind.ModuleBlock) {
|
||||
saveStateAndInvoke(node.body, body => addRange(statements, visitNodes(body.statements, namespaceElementVisitor, isStatement)));
|
||||
|
@ -2528,7 +2529,7 @@ export function transformTypeScript(context: TransformationContext) {
|
|||
statements.push(createExportMemberAssignmentStatement(node));
|
||||
}
|
||||
|
||||
function createNamespaceExport(exportName: Identifier, exportValue: Expression, location?: TextRange) {
|
||||
function createNamespaceExport(exportName: Identifier, exportValue: Expression, location?: ReadonlyTextRange) {
|
||||
return setTextRange(
|
||||
factory.createExpressionStatement(
|
||||
factory.createAssignment(
|
||||
|
@ -2540,7 +2541,7 @@ export function transformTypeScript(context: TransformationContext) {
|
|||
);
|
||||
}
|
||||
|
||||
function createNamespaceExportExpression(exportName: Identifier, exportValue: Expression, location?: TextRange) {
|
||||
function createNamespaceExportExpression(exportName: Identifier, exportValue: Expression, location?: ReadonlyTextRange) {
|
||||
return setTextRange(factory.createAssignment(getNamespaceMemberNameWithSourceMapsAndWithoutComments(exportName), exportValue), location);
|
||||
}
|
||||
|
||||
|
|
|
@ -1926,23 +1926,23 @@ export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration {
|
|||
|
||||
/** @internal */
|
||||
export interface PrivateIdentifierPropertyDeclaration extends PropertyDeclaration {
|
||||
name: PrivateIdentifier;
|
||||
readonly name: PrivateIdentifier;
|
||||
}
|
||||
/** @internal */
|
||||
export interface PrivateIdentifierAutoAccessorPropertyDeclaration extends AutoAccessorPropertyDeclaration {
|
||||
name: PrivateIdentifier;
|
||||
readonly name: PrivateIdentifier;
|
||||
}
|
||||
/** @internal */
|
||||
export interface PrivateIdentifierMethodDeclaration extends MethodDeclaration {
|
||||
name: PrivateIdentifier;
|
||||
readonly name: PrivateIdentifier;
|
||||
}
|
||||
/** @internal */
|
||||
export interface PrivateIdentifierGetAccessorDeclaration extends GetAccessorDeclaration {
|
||||
name: PrivateIdentifier;
|
||||
readonly name: PrivateIdentifier;
|
||||
}
|
||||
/** @internal */
|
||||
export interface PrivateIdentifierSetAccessorDeclaration extends SetAccessorDeclaration {
|
||||
name: PrivateIdentifier;
|
||||
readonly name: PrivateIdentifier;
|
||||
}
|
||||
/** @internal */
|
||||
export type PrivateIdentifierAccessorDeclaration = PrivateIdentifierGetAccessorDeclaration | PrivateIdentifierSetAccessorDeclaration;
|
||||
|
@ -4502,7 +4502,7 @@ export interface ScriptReferenceHost {
|
|||
}
|
||||
|
||||
export interface ParseConfigHost extends ModuleResolutionHost {
|
||||
useCaseSensitiveFileNames: boolean;
|
||||
readonly useCaseSensitiveFileNames: boolean;
|
||||
|
||||
readDirectory(rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[], depth?: number): readonly string[];
|
||||
|
||||
|
@ -7775,7 +7775,7 @@ export interface ModuleResolutionHost {
|
|||
realpath?(path: string): string;
|
||||
getCurrentDirectory?(): string;
|
||||
getDirectories?(path: string): string[];
|
||||
useCaseSensitiveFileNames?: boolean | (() => boolean) | undefined;
|
||||
readonly useCaseSensitiveFileNames?: boolean | (() => boolean) | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8080,7 +8080,7 @@ export const enum TransformFlags {
|
|||
// - Additional bitmasks
|
||||
}
|
||||
|
||||
export interface SourceMapRange extends TextRange {
|
||||
export interface SourceMapRange extends ReadonlyTextRange {
|
||||
source?: SourceMapSource;
|
||||
}
|
||||
|
||||
|
@ -8100,7 +8100,7 @@ export interface EmitNode {
|
|||
annotatedNodes?: Node[]; // Tracks Parse-tree nodes with EmitNodes for eventual cleanup.
|
||||
leadingComments?: SynthesizedComment[]; // Synthesized leading comments
|
||||
trailingComments?: SynthesizedComment[]; // Synthesized trailing comments
|
||||
commentRange?: TextRange; // The text range to use when emitting leading or trailing comments
|
||||
commentRange?: ReadonlyTextRange; // The text range to use when emitting leading or trailing comments
|
||||
sourceMapRange?: SourceMapRange; // The text range to use when emitting leading or trailing source mappings
|
||||
tokenSourceMapRanges?: (SourceMapRange | undefined)[]; // The text range to use when emitting source mappings for tokens
|
||||
constantValue?: string | number; // The constant value of an expression
|
||||
|
@ -9943,9 +9943,9 @@ export const enum PragmaKindFlags {
|
|||
|
||||
/** @internal */
|
||||
export interface PragmaArgumentSpecification<TName extends string> {
|
||||
name: TName; // Determines the name of the key in the resulting parsed type, type parameter to cause literal type inference
|
||||
optional?: boolean;
|
||||
captureSpan?: boolean;
|
||||
readonly name: TName; // Determines the name of the key in the resulting parsed type, type parameter to cause literal type inference
|
||||
readonly optional?: boolean;
|
||||
readonly captureSpan?: boolean;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
@ -10035,10 +10035,10 @@ export const enum JSDocParsingMode {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export type PragmaArgTypeMaybeCapture<TDesc> = TDesc extends { captureSpan: true; } ? { value: string; pos: number; end: number; } : string;
|
||||
export type PragmaArgTypeMaybeCapture<TDesc> = TDesc extends { readonly captureSpan: true; } ? { value: string; pos: number; end: number; } : string;
|
||||
|
||||
/** @internal */
|
||||
export type PragmaArgTypeOptional<TDesc, TName extends string> = TDesc extends { optional: true; } ? { [K in TName]?: PragmaArgTypeMaybeCapture<TDesc>; }
|
||||
export type PragmaArgTypeOptional<TDesc, TName extends string> = TDesc extends { readonly optional: true; } ? { [K in TName]?: PragmaArgTypeMaybeCapture<TDesc>; }
|
||||
: { [K in TName]: PragmaArgTypeMaybeCapture<TDesc>; };
|
||||
|
||||
/** @internal */
|
||||
|
@ -10046,7 +10046,7 @@ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) ex
|
|||
|
||||
/** @internal */
|
||||
export type ArgumentDefinitionToFieldUnion<T extends readonly PragmaArgumentSpecification<any>[]> = {
|
||||
[K in keyof T]: PragmaArgTypeOptional<T[K], T[K] extends { name: infer TName; } ? TName extends string ? TName : never : never>;
|
||||
[K in keyof T]: PragmaArgTypeOptional<T[K], T[K] extends { readonly name: infer TName; } ? TName extends string ? TName : never : never>;
|
||||
}[Extract<keyof T, number>]; // The mapped type maps over only the tuple members, but this reindex gets _all_ members - by extracting only `number` keys, we get only the tuple members
|
||||
|
||||
/**
|
||||
|
@ -10054,7 +10054,7 @@ export type ArgumentDefinitionToFieldUnion<T extends readonly PragmaArgumentSpec
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
export type PragmaArgumentType<KPrag extends keyof ConcretePragmaSpecs> = ConcretePragmaSpecs[KPrag] extends { args: readonly PragmaArgumentSpecification<any>[]; } ? UnionToIntersection<ArgumentDefinitionToFieldUnion<ConcretePragmaSpecs[KPrag]["args"]>>
|
||||
export type PragmaArgumentType<KPrag extends keyof ConcretePragmaSpecs> = ConcretePragmaSpecs[KPrag] extends { readonly args: readonly PragmaArgumentSpecification<any>[]; } ? UnionToIntersection<ArgumentDefinitionToFieldUnion<ConcretePragmaSpecs[KPrag]["args"]>>
|
||||
: never;
|
||||
|
||||
/** @internal */
|
||||
|
|
|
@ -2292,7 +2292,7 @@ export function createDiagnosticMessageChainFromDiagnostic(diagnostic: Diagnosti
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function createDiagnosticForRange(sourceFile: SourceFile, range: TextRange, message: DiagnosticMessage): DiagnosticWithLocation {
|
||||
export function createDiagnosticForRange(sourceFile: SourceFile, range: ReadonlyTextRange, message: DiagnosticMessage): DiagnosticWithLocation {
|
||||
return {
|
||||
file: sourceFile,
|
||||
start: range.pos,
|
||||
|
@ -5386,7 +5386,7 @@ export function nodeStartsNewLexicalEnvironment(node: Node): boolean {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function nodeIsSynthesized(range: TextRange): boolean {
|
||||
export function nodeIsSynthesized(range: ReadonlyTextRange): boolean {
|
||||
return positionIsSynthesized(range.pos)
|
||||
|| positionIsSynthesized(range.end);
|
||||
}
|
||||
|
@ -6684,7 +6684,7 @@ export function getEffectiveSetAccessorTypeAnnotationNode(node: SetAccessorDecla
|
|||
return parameter && getEffectiveTypeAnnotationNode(parameter);
|
||||
}
|
||||
|
||||
function emitNewLineBeforeLeadingComments(lineMap: readonly number[], writer: EmitTextWriter, node: TextRange, leadingComments: readonly CommentRange[] | undefined) {
|
||||
function emitNewLineBeforeLeadingComments(lineMap: readonly number[], writer: EmitTextWriter, node: ReadonlyTextRange, leadingComments: readonly CommentRange[] | undefined) {
|
||||
emitNewLineBeforeLeadingCommentsOfPosition(lineMap, writer, node.pos, leadingComments);
|
||||
}
|
||||
|
||||
|
@ -6752,7 +6752,7 @@ function emitComments(
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
export function emitDetachedComments(text: string, lineMap: readonly number[], writer: EmitTextWriter, writeComment: (text: string, lineMap: readonly number[], writer: EmitTextWriter, commentPos: number, commentEnd: number, newLine: string) => void, node: TextRange, newLine: string, removeComments: boolean) {
|
||||
export function emitDetachedComments(text: string, lineMap: readonly number[], writer: EmitTextWriter, writeComment: (text: string, lineMap: readonly number[], writer: EmitTextWriter, commentPos: number, commentEnd: number, newLine: string) => void, node: ReadonlyTextRange, newLine: string, removeComments: boolean) {
|
||||
let leadingComments: CommentRange[] | undefined;
|
||||
let currentDetachedCommentInfo: { nodePos: number; detachedCommentEndPos: number; } | undefined;
|
||||
if (removeComments) {
|
||||
|
@ -7580,7 +7580,7 @@ export function createRange(pos: number, end: number = pos): TextRange {
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
export function moveRangeEnd(range: TextRange, end: number): TextRange {
|
||||
export function moveRangeEnd(range: ReadonlyTextRange, end: number): TextRange {
|
||||
return createRange(range.pos, end);
|
||||
}
|
||||
|
||||
|
@ -7592,7 +7592,7 @@ export function moveRangeEnd(range: TextRange, end: number): TextRange {
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
export function moveRangePos(range: TextRange, pos: number): TextRange {
|
||||
export function moveRangePos(range: ReadonlyTextRange, pos: number): TextRange {
|
||||
return createRange(pos, range.end);
|
||||
}
|
||||
|
||||
|
@ -7601,7 +7601,7 @@ export function moveRangePos(range: TextRange, pos: number): TextRange {
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
export function moveRangePastDecorators(node: Node): TextRange {
|
||||
export function moveRangePastDecorators(node: Node): ReadonlyTextRange {
|
||||
const lastDecorator = canHaveModifiers(node) ? findLast(node.modifiers, isDecorator) : undefined;
|
||||
return lastDecorator && !positionIsSynthesized(lastDecorator.end)
|
||||
? moveRangePos(node, lastDecorator.end)
|
||||
|
@ -7613,7 +7613,7 @@ export function moveRangePastDecorators(node: Node): TextRange {
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
export function moveRangePastModifiers(node: Node): TextRange {
|
||||
export function moveRangePastModifiers(node: Node): ReadonlyTextRange {
|
||||
if (isPropertyDeclaration(node) || isMethodDeclaration(node)) {
|
||||
return moveRangePos(node, node.name.pos);
|
||||
}
|
||||
|
@ -7637,12 +7637,12 @@ export function createTokenRange(pos: number, token: SyntaxKind): TextRange {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeIsOnSingleLine(range: TextRange, sourceFile: SourceFile) {
|
||||
export function rangeIsOnSingleLine(range: ReadonlyTextRange, sourceFile: SourceFile) {
|
||||
return rangeStartIsOnSameLineAsRangeEnd(range, range, sourceFile);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeStartPositionsAreOnSameLine(range1: TextRange, range2: TextRange, sourceFile: SourceFile) {
|
||||
export function rangeStartPositionsAreOnSameLine(range1: ReadonlyTextRange, range2: ReadonlyTextRange, sourceFile: SourceFile) {
|
||||
return positionsAreOnSameLine(
|
||||
getStartPositionOfRange(range1, sourceFile, /*includeComments*/ false),
|
||||
getStartPositionOfRange(range2, sourceFile, /*includeComments*/ false),
|
||||
|
@ -7651,28 +7651,28 @@ export function rangeStartPositionsAreOnSameLine(range1: TextRange, range2: Text
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeEndPositionsAreOnSameLine(range1: TextRange, range2: TextRange, sourceFile: SourceFile) {
|
||||
export function rangeEndPositionsAreOnSameLine(range1: ReadonlyTextRange, range2: ReadonlyTextRange, sourceFile: SourceFile) {
|
||||
return positionsAreOnSameLine(range1.end, range2.end, sourceFile);
|
||||
}
|
||||
|
||||
/** @internal @knipignore */
|
||||
export function rangeStartIsOnSameLineAsRangeEnd(range1: TextRange, range2: TextRange, sourceFile: SourceFile) {
|
||||
export function rangeStartIsOnSameLineAsRangeEnd(range1: ReadonlyTextRange, range2: ReadonlyTextRange, sourceFile: SourceFile) {
|
||||
return positionsAreOnSameLine(getStartPositionOfRange(range1, sourceFile, /*includeComments*/ false), range2.end, sourceFile);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeEndIsOnSameLineAsRangeStart(range1: TextRange, range2: TextRange, sourceFile: SourceFile) {
|
||||
export function rangeEndIsOnSameLineAsRangeStart(range1: ReadonlyTextRange, range2: ReadonlyTextRange, sourceFile: SourceFile) {
|
||||
return positionsAreOnSameLine(range1.end, getStartPositionOfRange(range2, sourceFile, /*includeComments*/ false), sourceFile);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getLinesBetweenRangeEndAndRangeStart(range1: TextRange, range2: TextRange, sourceFile: SourceFile, includeSecondRangeComments: boolean) {
|
||||
export function getLinesBetweenRangeEndAndRangeStart(range1: ReadonlyTextRange, range2: ReadonlyTextRange, sourceFile: SourceFile, includeSecondRangeComments: boolean) {
|
||||
const range2Start = getStartPositionOfRange(range2, sourceFile, includeSecondRangeComments);
|
||||
return getLinesBetweenPositions(sourceFile, range1.end, range2Start);
|
||||
}
|
||||
|
||||
/** @internal @knipignore */
|
||||
export function getLinesBetweenRangeEndPositions(range1: TextRange, range2: TextRange, sourceFile: SourceFile) {
|
||||
export function getLinesBetweenRangeEndPositions(range1: ReadonlyTextRange, range2: ReadonlyTextRange, sourceFile: SourceFile) {
|
||||
return getLinesBetweenPositions(sourceFile, range1.end, range2.end);
|
||||
}
|
||||
|
||||
|
@ -7687,7 +7687,7 @@ export function positionsAreOnSameLine(pos1: number, pos2: number, sourceFile: S
|
|||
}
|
||||
|
||||
/** @internal @knipignore */
|
||||
export function getStartPositionOfRange(range: TextRange, sourceFile: SourceFile, includeComments: boolean) {
|
||||
export function getStartPositionOfRange(range: ReadonlyTextRange, sourceFile: SourceFile, includeComments: boolean) {
|
||||
return positionIsSynthesized(range.pos) ? -1 : skipTrivia(sourceFile.text, range.pos, /*stopAfterLineBreak*/ false, includeComments);
|
||||
}
|
||||
|
||||
|
|
|
@ -256,6 +256,7 @@ import {
|
|||
PropertyAccessExpression,
|
||||
PropertyName,
|
||||
QualifiedName,
|
||||
ReadonlyTextRange,
|
||||
ScriptTarget,
|
||||
SetAccessorDeclaration,
|
||||
setLocalizedDiagnosticMessages,
|
||||
|
@ -343,7 +344,7 @@ export function textSpanContainsPosition(span: TextSpan, position: number) {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function textRangeContainsPositionInclusive(range: TextRange, position: number): boolean {
|
||||
export function textRangeContainsPositionInclusive(range: ReadonlyTextRange, position: number): boolean {
|
||||
return position >= range.pos && position <= range.end;
|
||||
}
|
||||
|
||||
|
@ -353,12 +354,12 @@ export function textSpanContainsTextSpan(span: TextSpan, other: TextSpan) {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function textSpanContainsTextRange(span: TextSpan, range: TextRange) {
|
||||
export function textSpanContainsTextRange(span: TextSpan, range: ReadonlyTextRange) {
|
||||
return range.pos >= span.start && range.end <= textSpanEnd(span);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function textRangeContainsTextSpan(range: TextRange, span: TextSpan) {
|
||||
export function textRangeContainsTextSpan(range: ReadonlyTextRange, span: TextSpan) {
|
||||
return span.start >= range.pos && textSpanEnd(span) <= range.end;
|
||||
}
|
||||
|
||||
|
@ -390,7 +391,7 @@ export function textSpanIntersectsWithPosition(span: TextSpan, position: number)
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function textRangeIntersectsWithTextSpan(range: TextRange, span: TextSpan): boolean {
|
||||
export function textRangeIntersectsWithTextSpan(range: ReadonlyTextRange, span: TextSpan): boolean {
|
||||
return textSpanIntersectsWith(span, range.pos, range.end - range.pos);
|
||||
}
|
||||
|
||||
|
|
|
@ -673,7 +673,7 @@ export interface WatchFactoryHost {
|
|||
watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number, options?: WatchOptions): FileWatcher;
|
||||
watchDirectory(path: string, callback: DirectoryWatcherCallback, recursive?: boolean, options?: WatchOptions): FileWatcher;
|
||||
getCurrentDirectory?(): string;
|
||||
useCaseSensitiveFileNames: boolean | (() => boolean);
|
||||
readonly useCaseSensitiveFileNames: boolean | (() => boolean);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
|
|
@ -248,7 +248,7 @@ export class CompilerHost implements ts.CompilerHost {
|
|||
private readonly _outputsMap: collections.SortedMap<string, number>;
|
||||
public readonly traces: string[] = [];
|
||||
public readonly shouldAssertInvariants = !Harness.lightMode;
|
||||
public readonly jsDocParsingMode: ts.JSDocParsingMode | undefined;
|
||||
public jsDocParsingMode: ts.JSDocParsingMode | undefined;
|
||||
|
||||
private _setParentNodes: boolean;
|
||||
private _sourceFiles: collections.SortedMap<string, ts.SourceFile>;
|
||||
|
|
|
@ -4162,7 +4162,7 @@ export class TestState {
|
|||
this.verifyNewContent({ newFileContent: options.newFileContents }, editInfo.edits);
|
||||
}
|
||||
|
||||
private testNewFileContents(edits: readonly ts.FileTextChanges[], newFileContents: { [fileName: string]: string; }, description: string): void {
|
||||
private testNewFileContents(edits: readonly ts.FileTextChanges[], newFileContents: { readonly [fileName: string]: string; }, description: string): void {
|
||||
for (const { fileName, textChanges } of edits) {
|
||||
const newContent = newFileContents[fileName];
|
||||
if (newContent === undefined) {
|
||||
|
|
|
@ -98,7 +98,7 @@ export interface EndInstallTypes extends InstallTypes {
|
|||
}
|
||||
|
||||
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {
|
||||
useCaseSensitiveFileNames: boolean;
|
||||
readonly useCaseSensitiveFileNames: boolean;
|
||||
writeFile(path: string, content: string): void;
|
||||
createDirectory(path: string): void;
|
||||
getCurrentDirectory?(): string;
|
||||
|
|
|
@ -52,6 +52,7 @@ class EditWalker implements LineIndexWalker {
|
|||
get done() {
|
||||
return false;
|
||||
}
|
||||
set done(value) {}
|
||||
|
||||
readonly lineIndex = new LineIndex();
|
||||
// path to start of range
|
||||
|
|
|
@ -450,7 +450,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog
|
|||
const nonTypeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ false);
|
||||
const typeOnlyEntry = newImports.get(typeOnlyKey);
|
||||
const nonTypeOnlyEntry = newImports.get(nonTypeOnlyKey);
|
||||
const newEntry: ImportsCollection & { useRequire: boolean; } = {
|
||||
const newEntry: Mutable<ImportsCollection & { useRequire: boolean; }> = {
|
||||
defaultImport: undefined,
|
||||
namedImports: undefined,
|
||||
namespaceLikeImport: undefined,
|
||||
|
@ -1930,11 +1930,11 @@ interface ImportsCollection {
|
|||
};
|
||||
}
|
||||
|
||||
function needsTypeOnly({ addAsTypeOnly }: { addAsTypeOnly: AddAsTypeOnly; }): boolean {
|
||||
function needsTypeOnly({ addAsTypeOnly }: { readonly addAsTypeOnly: AddAsTypeOnly; }): boolean {
|
||||
return addAsTypeOnly === AddAsTypeOnly.Required;
|
||||
}
|
||||
|
||||
function shouldUseTypeOnly(info: { addAsTypeOnly: AddAsTypeOnly; }, preferences: UserPreferences): boolean {
|
||||
function shouldUseTypeOnly(info: { readonly addAsTypeOnly: AddAsTypeOnly; }, preferences: UserPreferences): boolean {
|
||||
return needsTypeOnly(info) || !!preferences.preferTypeOnlyAutoImports && info.addAsTypeOnly !== AddAsTypeOnly.NotAllowed;
|
||||
}
|
||||
|
||||
|
@ -1943,7 +1943,7 @@ function getNewImports(
|
|||
quotePreference: QuotePreference,
|
||||
defaultImport: Import | undefined,
|
||||
namedImports: readonly Import[] | undefined,
|
||||
namespaceLikeImport: Import & { importKind: ImportKind.CommonJS | ImportKind.Namespace; } | undefined,
|
||||
namespaceLikeImport: Import & { readonly importKind: ImportKind.CommonJS | ImportKind.Namespace; } | undefined,
|
||||
compilerOptions: CompilerOptions,
|
||||
preferences: UserPreferences,
|
||||
): AnyImportSyntax | readonly AnyImportSyntax[] {
|
||||
|
|
|
@ -66,6 +66,7 @@ import {
|
|||
rangeContainsRange,
|
||||
rangeContainsStartEnd,
|
||||
rangeOverlapsWithStartEnd,
|
||||
ReadonlyTextRange,
|
||||
repeatString,
|
||||
SourceFile,
|
||||
SourceFileLike,
|
||||
|
@ -86,8 +87,8 @@ export interface FormatContext {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export interface TextRangeWithKind<T extends SyntaxKind = SyntaxKind> extends TextRange {
|
||||
kind: T;
|
||||
export interface TextRangeWithKind<T extends SyntaxKind = SyntaxKind> extends ReadonlyTextRange {
|
||||
readonly kind: T;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
@ -327,7 +328,7 @@ function findEnclosingNode(range: TextRange, sourceFile: SourceFile): Node {
|
|||
* This function will return a predicate that for a given text range will tell
|
||||
* if there are any parse errors that overlap with the range.
|
||||
*/
|
||||
function prepareRangeContainsErrorFunction(errors: readonly Diagnostic[], originalRange: TextRange): (r: TextRange) => boolean {
|
||||
function prepareRangeContainsErrorFunction(errors: readonly Diagnostic[], originalRange: ReadonlyTextRange): (r: ReadonlyTextRange) => boolean {
|
||||
if (!errors.length) {
|
||||
return rangeHasNoErrors;
|
||||
}
|
||||
|
@ -494,7 +495,7 @@ function formatSpanWorker(
|
|||
formattingScanner: FormattingScanner,
|
||||
{ options, getRules, host }: FormatContext,
|
||||
requestKind: FormattingRequestKind,
|
||||
rangeContainsError: (r: TextRange) => boolean,
|
||||
rangeContainsError: (r: ReadonlyTextRange) => boolean,
|
||||
sourceFile: SourceFileLike,
|
||||
): TextChange[] {
|
||||
// formatting context is used by rules provider
|
||||
|
@ -1181,7 +1182,7 @@ function formatSpanWorker(
|
|||
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
|
||||
}
|
||||
|
||||
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean, indentFinalLine = true) {
|
||||
function indentMultilineComment(commentRange: ReadonlyTextRange, indentation: number, firstLineIsIndented: boolean, indentFinalLine = true) {
|
||||
// split comment in lines
|
||||
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
|
||||
const endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line;
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
isTrivia,
|
||||
LanguageVariant,
|
||||
last,
|
||||
Mutable,
|
||||
Node,
|
||||
NodeArray,
|
||||
ScriptTarget,
|
||||
|
@ -308,7 +309,7 @@ export function getFormattingScanner<T>(text: string, languageVariant: LanguageV
|
|||
// when parser interprets token differently, i.e keyword treated as identifier
|
||||
function fixTokenKind(tokenInfo: TokenInfo, container: Node): TokenInfo {
|
||||
if (isToken(container) && tokenInfo.token.kind !== container.kind) {
|
||||
tokenInfo.token.kind = container.kind;
|
||||
(tokenInfo.token as Mutable<TextRangeWithKind>).kind = container.kind;
|
||||
}
|
||||
return tokenInfo;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import {
|
|||
positionBelongsToNode,
|
||||
rangeContainsRange,
|
||||
rangeContainsStartEnd,
|
||||
ReadonlyTextRange,
|
||||
SignatureDeclaration,
|
||||
skipTrivia,
|
||||
SourceFile,
|
||||
|
@ -532,7 +533,7 @@ export namespace SmartIndenter {
|
|||
}
|
||||
}
|
||||
|
||||
function getVisualListRange(node: Node, list: TextRange, sourceFile: SourceFile): TextRange {
|
||||
function getVisualListRange(node: Node, list: ReadonlyTextRange, sourceFile: SourceFile): ReadonlyTextRange {
|
||||
const children = node.getChildren(sourceFile);
|
||||
for (let i = 1; i < children.length - 1; i++) {
|
||||
if (children[i].pos === list.pos && children[i].end === list.end) {
|
||||
|
|
|
@ -138,7 +138,7 @@ export const enum ImportExport {
|
|||
}
|
||||
|
||||
interface AmbientModuleDeclaration extends ModuleDeclaration {
|
||||
body?: ModuleBlock;
|
||||
readonly body?: ModuleBlock;
|
||||
}
|
||||
type SourceFileLike = SourceFile | AmbientModuleDeclaration;
|
||||
// Identifier for the case of `const x = require("y")`.
|
||||
|
|
|
@ -311,13 +311,13 @@ function matchNode(a: Node, b: Node): boolean {
|
|||
return false;
|
||||
}
|
||||
|
||||
function wipeNode(node: Mutable<Node>) {
|
||||
function wipeNode(node: Node) {
|
||||
resetNodePositions(node);
|
||||
node.parent = undefined!;
|
||||
(node as Mutable<Node>).parent = undefined!;
|
||||
}
|
||||
|
||||
function resetNodePositions(node: Mutable<Node>) {
|
||||
node.pos = -1;
|
||||
node.end = -1;
|
||||
function resetNodePositions(node: Node) {
|
||||
(node as Mutable<Node>).pos = -1;
|
||||
(node as Mutable<Node>).end = -1;
|
||||
node.forEachChild(resetNodePositions);
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ import {
|
|||
positionIsSynthesized,
|
||||
PropertyAccessExpression,
|
||||
rangeContainsStartEnd,
|
||||
ReadonlyTextRange,
|
||||
RefactorActionInfo,
|
||||
RefactorContext,
|
||||
RefactorEditInfo,
|
||||
|
@ -917,7 +918,7 @@ interface ScopeExtractions {
|
|||
* Each returned ExtractResultForScope corresponds to a possible target scope and is either a set of changes
|
||||
* or an error explaining why we can't extract into that scope.
|
||||
*/
|
||||
function getPossibleExtractions(targetRange: TargetRange, context: RefactorContext): { readonly affectedTextRange: TextRange; readonly extractions: ScopeExtractions[] | undefined; } {
|
||||
function getPossibleExtractions(targetRange: TargetRange, context: RefactorContext): { readonly affectedTextRange: ReadonlyTextRange; readonly extractions: ScopeExtractions[] | undefined; } {
|
||||
const { scopes, affectedTextRange, readsAndWrites: { functionErrorsPerScope, constantErrorsPerScope } } = getPossibleExtractionsWorker(targetRange, context);
|
||||
// Need the inner type annotation to avoid https://github.com/Microsoft/TypeScript/issues/7547
|
||||
const extractions = scopes.map((scope, i): ScopeExtractions => {
|
||||
|
@ -964,7 +965,7 @@ function getPossibleExtractions(targetRange: TargetRange, context: RefactorConte
|
|||
return { affectedTextRange, extractions };
|
||||
}
|
||||
|
||||
function getPossibleExtractionsWorker(targetRange: TargetRange, context: RefactorContext): { readonly scopes: Scope[]; readonly affectedTextRange: TextRange; readonly readsAndWrites: ReadsAndWrites; } {
|
||||
function getPossibleExtractionsWorker(targetRange: TargetRange, context: RefactorContext): { readonly scopes: Scope[]; readonly affectedTextRange: ReadonlyTextRange; readonly readsAndWrites: ReadsAndWrites; } {
|
||||
const { file: sourceFile } = context;
|
||||
|
||||
const scopes = collectEnclosingScopes(targetRange);
|
||||
|
@ -1787,7 +1788,7 @@ function isReadonlyArray(v: any): v is readonly any[] {
|
|||
* var someThing = foo + bar;
|
||||
* this returns ^-------^
|
||||
*/
|
||||
function getEnclosingTextRange(targetRange: TargetRange, sourceFile: SourceFile): TextRange {
|
||||
function getEnclosingTextRange(targetRange: TargetRange, sourceFile: SourceFile): ReadonlyTextRange {
|
||||
return isReadonlyArray(targetRange.range)
|
||||
? { pos: first(targetRange.range).getStart(sourceFile), end: last(targetRange.range).getEnd() }
|
||||
: targetRange.range;
|
||||
|
@ -1822,7 +1823,7 @@ interface ReadsAndWrites {
|
|||
function collectReadsAndWrites(
|
||||
targetRange: TargetRange,
|
||||
scopes: Scope[],
|
||||
enclosingTextRange: TextRange,
|
||||
enclosingTextRange: ReadonlyTextRange,
|
||||
sourceFile: SourceFile,
|
||||
checker: TypeChecker,
|
||||
cancellationToken: CancellationToken,
|
||||
|
|
|
@ -53,6 +53,7 @@ import {
|
|||
nodeOverlapsWithStartEnd,
|
||||
pushIfUnique,
|
||||
rangeContainsStartEnd,
|
||||
ReadonlyTextRange,
|
||||
RefactorContext,
|
||||
RefactorEditInfo,
|
||||
setEmitFlags,
|
||||
|
@ -267,7 +268,7 @@ function flattenTypeLiteralNodeReference(checker: TypeChecker, selection: TypeNo
|
|||
return undefined;
|
||||
}
|
||||
|
||||
function rangeContainsSkipTrivia(r1: TextRange, node: TextRange, file: SourceFile): boolean {
|
||||
function rangeContainsSkipTrivia(r1: ReadonlyTextRange, node: ReadonlyTextRange, file: SourceFile): boolean {
|
||||
return rangeContainsStartEnd(r1, skipTrivia(file.text, node.pos), node.end);
|
||||
}
|
||||
|
||||
|
|
|
@ -3516,7 +3516,7 @@ function getContainingObjectLiteralElementWorker(node: Node): ObjectLiteralEleme
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export type ObjectLiteralElementWithName = ObjectLiteralElement & { name: PropertyName; parent: ObjectLiteralExpression | JsxAttributes; };
|
||||
export type ObjectLiteralElementWithName = ObjectLiteralElement & { readonly name: PropertyName; readonly parent: ObjectLiteralExpression | JsxAttributes; };
|
||||
|
||||
function getSymbolAtLocationForQuickInfo(node: Node, checker: TypeChecker): Symbol | undefined {
|
||||
const object = getContainingObjectLiteralElement(node);
|
||||
|
|
|
@ -123,6 +123,7 @@ import {
|
|||
MethodSignature,
|
||||
Modifier,
|
||||
MultiMap,
|
||||
Mutable,
|
||||
NamedImportBindings,
|
||||
NamedImports,
|
||||
NamespaceImport,
|
||||
|
@ -145,6 +146,7 @@ import {
|
|||
rangeOfNode,
|
||||
rangeOfTypeParameters,
|
||||
rangeStartPositionsAreOnSameLine,
|
||||
ReadonlyTextRange,
|
||||
removeSuffix,
|
||||
ScriptKind,
|
||||
ScriptTarget,
|
||||
|
@ -180,24 +182,24 @@ import {
|
|||
* Currently for simplicity we store recovered positions on the node itself.
|
||||
* It can be changed to side-table later if we decide that current design is too invasive.
|
||||
*/
|
||||
function getPos(n: TextRange): number {
|
||||
function getPos(n: ReadonlyTextRange): number {
|
||||
const result = (n as any).__pos;
|
||||
Debug.assert(typeof result === "number");
|
||||
return result;
|
||||
}
|
||||
|
||||
function setPos(n: TextRange, pos: number): void {
|
||||
function setPos(n: ReadonlyTextRange, pos: number): void {
|
||||
Debug.assert(typeof pos === "number");
|
||||
(n as any).__pos = pos;
|
||||
}
|
||||
|
||||
function getEnd(n: TextRange): number {
|
||||
function getEnd(n: ReadonlyTextRange): number {
|
||||
const result = (n as any).__end;
|
||||
Debug.assert(typeof result === "number");
|
||||
return result;
|
||||
}
|
||||
|
||||
function setEnd(n: TextRange, end: number): void {
|
||||
function setEnd(n: ReadonlyTextRange, end: number): void {
|
||||
Debug.assert(typeof end === "number");
|
||||
(n as any).__end = end;
|
||||
}
|
||||
|
@ -316,7 +318,7 @@ type Change = ReplaceWithSingleNode | ReplaceWithMultipleNodes | RemoveNode | Ch
|
|||
|
||||
interface BaseChange {
|
||||
readonly sourceFile: SourceFile;
|
||||
readonly range: TextRange;
|
||||
readonly range: ReadonlyTextRange;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
@ -493,7 +495,7 @@ export function isThisTypeAnnotatable(containingFunction: SignatureDeclaration):
|
|||
export class ChangeTracker {
|
||||
private readonly changes: Change[] = [];
|
||||
private newFileChanges?: MultiMap<string, NewFileInsertion>;
|
||||
private readonly classesWithNodesInsertedAtStart = new Map<number, { readonly node: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression; readonly sourceFile: SourceFile; }>(); // Set<ClassDeclaration> implemented as Map<node id, ClassDeclaration>
|
||||
private readonly classesWithNodesInsertedAtStart = new Map<number, { readonly node: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression | TypeLiteralNode | EnumDeclaration; readonly sourceFile: SourceFile; }>(); // Set<ClassDeclaration> implemented as Map<node id, ClassDeclaration>
|
||||
private readonly deletedNodes: { readonly sourceFile: SourceFile; readonly node: Node | NodeArray<TypeParameterDeclaration>; }[] = [];
|
||||
|
||||
public static fromContext(context: TextChangesContext): ChangeTracker {
|
||||
|
@ -521,7 +523,7 @@ export class ChangeTracker {
|
|||
}
|
||||
}
|
||||
|
||||
public deleteRange(sourceFile: SourceFile, range: TextRange): void {
|
||||
public deleteRange(sourceFile: SourceFile, range: ReadonlyTextRange): void {
|
||||
this.changes.push({ kind: ChangeKind.Remove, sourceFile, range });
|
||||
}
|
||||
|
||||
|
@ -562,7 +564,7 @@ export class ChangeTracker {
|
|||
this.deleteRange(sourceFile, { pos: startPosition, end: endPosition });
|
||||
}
|
||||
|
||||
public replaceRange(sourceFile: SourceFile, range: TextRange, newNode: Node, options: InsertNodeOptions = {}): void {
|
||||
public replaceRange(sourceFile: SourceFile, range: ReadonlyTextRange, newNode: Node, options: InsertNodeOptions = {}): void {
|
||||
this.changes.push({ kind: ChangeKind.ReplaceWithSingleNode, sourceFile, range, options, node: newNode });
|
||||
}
|
||||
|
||||
|
@ -574,7 +576,7 @@ export class ChangeTracker {
|
|||
this.replaceRange(sourceFile, getAdjustedRange(sourceFile, startNode, endNode, options), newNode, options);
|
||||
}
|
||||
|
||||
private replaceRangeWithNodes(sourceFile: SourceFile, range: TextRange, newNodes: readonly Node[], options: ReplaceWithMultipleNodesOptions & ConfigurableStartEnd = {}): void {
|
||||
private replaceRangeWithNodes(sourceFile: SourceFile, range: ReadonlyTextRange, newNodes: readonly Node[], options: ReplaceWithMultipleNodesOptions & ConfigurableStartEnd = {}): void {
|
||||
this.changes.push({ kind: ChangeKind.ReplaceWithMultipleNodes, sourceFile, range, options, nodes: newNodes });
|
||||
}
|
||||
|
||||
|
@ -744,7 +746,7 @@ export class ChangeTracker {
|
|||
this.replaceJSDocComment(sourceFile, parent, filter(flatMapToMutable(parent.jsDoc, j => j.tags), predicate));
|
||||
}
|
||||
|
||||
public replaceRangeWithText(sourceFile: SourceFile, range: TextRange, text: string): void {
|
||||
public replaceRangeWithText(sourceFile: SourceFile, range: ReadonlyTextRange, text: string): void {
|
||||
this.changes.push({ kind: ChangeKind.Text, sourceFile, range, text });
|
||||
}
|
||||
|
||||
|
@ -864,7 +866,7 @@ export class ChangeTracker {
|
|||
*/
|
||||
private guessIndentationFromExistingMembers(sourceFile: SourceFile, node: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression | TypeLiteralNode | EnumDeclaration) {
|
||||
let indentation: number | undefined;
|
||||
let lastRange: TextRange = node;
|
||||
let lastRange: ReadonlyTextRange = node;
|
||||
for (const member of getMembersOrProperties(node)) {
|
||||
if (rangeStartPositionsAreOnSameLine(lastRange, member, sourceFile)) {
|
||||
// each indented member must be on a new line
|
||||
|
@ -1246,7 +1248,7 @@ function endPositionToDeleteNodeInList(sourceFile: SourceFile, node: Node, prevN
|
|||
return end;
|
||||
}
|
||||
|
||||
function getClassOrObjectBraceEnds(cls: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression, sourceFile: SourceFile): [number | undefined, number | undefined] {
|
||||
function getClassOrObjectBraceEnds(cls: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression | TypeLiteralNode | EnumDeclaration, sourceFile: SourceFile): [number | undefined, number | undefined] {
|
||||
const open = findChildOfKind(cls, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
const close = findChildOfKind(cls, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
return [open?.end, close?.end];
|
||||
|
|
|
@ -977,9 +977,9 @@ export interface CombinedCodeActions {
|
|||
export type CodeActionCommand = InstallPackageAction;
|
||||
|
||||
export interface InstallPackageAction {
|
||||
/** @internal */ readonly type: "install package";
|
||||
/** @internal */ readonly file: string;
|
||||
/** @internal */ readonly packageName: string;
|
||||
/** @internal */ type: "install package";
|
||||
/** @internal */ file: string;
|
||||
/** @internal */ packageName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -317,6 +317,7 @@ import {
|
|||
PseudoBigInt,
|
||||
pseudoBigIntToString,
|
||||
QualifiedName,
|
||||
ReadonlyTextRange,
|
||||
RefactorContext,
|
||||
removeFileExtension,
|
||||
removeSuffix,
|
||||
|
@ -915,37 +916,37 @@ export function getLineStartPositionForPosition(position: number, sourceFile: So
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeContainsRange(r1: TextRange, r2: TextRange): boolean {
|
||||
export function rangeContainsRange(r1: ReadonlyTextRange, r2: ReadonlyTextRange): boolean {
|
||||
return startEndContainsRange(r1.pos, r1.end, r2);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeContainsRangeExclusive(r1: TextRange, r2: TextRange): boolean {
|
||||
export function rangeContainsRangeExclusive(r1: ReadonlyTextRange, r2: ReadonlyTextRange): boolean {
|
||||
return rangeContainsPositionExclusive(r1, r2.pos) && rangeContainsPositionExclusive(r1, r2.end);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeContainsPosition(r: TextRange, pos: number): boolean {
|
||||
export function rangeContainsPosition(r: ReadonlyTextRange, pos: number): boolean {
|
||||
return r.pos <= pos && pos <= r.end;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeContainsPositionExclusive(r: TextRange, pos: number) {
|
||||
export function rangeContainsPositionExclusive(r: ReadonlyTextRange, pos: number) {
|
||||
return r.pos < pos && pos < r.end;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function startEndContainsRange(start: number, end: number, range: TextRange): boolean {
|
||||
export function startEndContainsRange(start: number, end: number, range: ReadonlyTextRange): boolean {
|
||||
return start <= range.pos && end >= range.end;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeContainsStartEnd(range: TextRange, start: number, end: number): boolean {
|
||||
export function rangeContainsStartEnd(range: ReadonlyTextRange, start: number, end: number): boolean {
|
||||
return range.pos <= start && range.end >= end;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function rangeOverlapsWithStartEnd(r1: TextRange, start: number, end: number) {
|
||||
export function rangeOverlapsWithStartEnd(r1: ReadonlyTextRange, start: number, end: number) {
|
||||
return startEndOverlapsWithStartEnd(r1.pos, r1.end, start, end);
|
||||
}
|
||||
|
||||
|
@ -2344,7 +2345,7 @@ export function createTextRangeFromNode(node: Node, sourceFile: SourceFile): Tex
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export function createTextSpanFromRange(range: TextRange): TextSpan {
|
||||
export function createTextSpanFromRange(range: ReadonlyTextRange): TextSpan {
|
||||
return createTextSpanFromBounds(range.pos, range.end);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import {
|
|||
} from "../_namespaces/Harness.Parallel.js";
|
||||
import * as ts from "../_namespaces/ts.js";
|
||||
import * as Utils from "../_namespaces/Utils.js";
|
||||
import { WritableStream } from "stream/web";
|
||||
|
||||
export function start(importTests: () => Promise<unknown>) {
|
||||
const Base = Mocha.reporters.Base;
|
||||
|
@ -173,16 +174,16 @@ export function start(importTests: () => Promise<unknown>) {
|
|||
}
|
||||
|
||||
cursor.hide();
|
||||
readline.moveCursor(process.stdout, -process.stdout.columns, -this._lineCount);
|
||||
readline.moveCursor(process.stdout as NodeJS.WritableStream, -process.stdout.columns, -this._lineCount);
|
||||
let lineCount = 0;
|
||||
const numProgressBars = this._progressBars.length;
|
||||
for (let i = 0; i < numProgressBars; i++) {
|
||||
if (i === index) {
|
||||
readline.clearLine(process.stdout, 1);
|
||||
readline.clearLine(process.stdout as NodeJS.WritableStream, 1);
|
||||
process.stdout.write(this._progressBars[i].text + os.EOL);
|
||||
}
|
||||
else {
|
||||
readline.moveCursor(process.stdout, -process.stdout.columns, +1);
|
||||
readline.moveCursor(process.stdout as NodeJS.WritableStream, -process.stdout.columns, +1);
|
||||
}
|
||||
|
||||
lineCount++;
|
||||
|
|
|
@ -125,9 +125,9 @@ interface ProjectTestConfiguration {
|
|||
}
|
||||
|
||||
interface ProjectTestPayload {
|
||||
testCase: ProjectRunnerTestCase & ts.CompilerOptions;
|
||||
moduleKind: ts.ModuleKind;
|
||||
vfs: vfs.FileSystem;
|
||||
readonly testCase: ProjectRunnerTestCase & ts.CompilerOptions;
|
||||
readonly moduleKind: ts.ModuleKind;
|
||||
readonly vfs: vfs.FileSystem;
|
||||
}
|
||||
|
||||
class ProjectTestCase {
|
||||
|
|
|
@ -353,7 +353,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
|
|||
|
||||
readonly watchUtils: WatchUtils<TestFileWatcher, TestFsWatcher>;
|
||||
runWithFallbackPolling: boolean;
|
||||
public readonly useCaseSensitiveFileNames: boolean;
|
||||
public useCaseSensitiveFileNames: boolean;
|
||||
public readonly newLine: string;
|
||||
public readonly windowsStyleRoot?: string;
|
||||
private readonly environmentVariables?: Map<string, string>;
|
||||
|
|
|
@ -62,8 +62,8 @@ describe("unittests:: tsserver:: completions::", () => {
|
|||
});
|
||||
|
||||
interface CompletionDetailsFullRequest extends ts.server.protocol.FileLocationRequest {
|
||||
readonly command: ts.server.protocol.CommandTypes.CompletionDetailsFull;
|
||||
readonly arguments: ts.server.protocol.CompletionDetailsRequestArgs;
|
||||
command: ts.server.protocol.CommandTypes.CompletionDetailsFull;
|
||||
arguments: ts.server.protocol.CompletionDetailsRequestArgs;
|
||||
}
|
||||
session.executeCommandSeq<CompletionDetailsFullRequest>({
|
||||
command: ts.server.protocol.CommandTypes.CompletionDetailsFull,
|
||||
|
|
|
@ -251,7 +251,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
|||
});
|
||||
|
||||
interface ReferencesFullRequest extends ts.server.protocol.FileLocationRequest {
|
||||
readonly command: ts.server.protocol.CommandTypes.ReferencesFull;
|
||||
command: ts.server.protocol.CommandTypes.ReferencesFull;
|
||||
}
|
||||
it("findAllReferencesFull", () => {
|
||||
const session = makeSampleProjects();
|
||||
|
|
|
@ -392,7 +392,7 @@ function parseEventPort(eventPortStr: string | undefined) {
|
|||
function startNodeSession(options: StartSessionOptions, logger: ts.server.Logger, cancellationToken: ts.server.ServerCancellationToken) {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
output: process.stdout as NodeJS.WritableStream,
|
||||
terminal: false,
|
||||
});
|
||||
|
||||
|
|
|
@ -405,15 +405,16 @@ export abstract class TypingsInstaller {
|
|||
const requestId = this.installRunCount;
|
||||
this.installRunCount++;
|
||||
|
||||
const scopedTypings = filteredTypings.map(typingsName);
|
||||
// send progress event
|
||||
this.sendResponse({
|
||||
kind: EventBeginInstallTypes,
|
||||
eventId: requestId,
|
||||
typingsInstallerVersion: version,
|
||||
projectName: req.projectName,
|
||||
packagesToInstall: scopedTypings,
|
||||
} as BeginInstallTypes);
|
||||
|
||||
const scopedTypings = filteredTypings.map(typingsName);
|
||||
this.installTypingsAsync(requestId, scopedTypings, cachePath, ok => {
|
||||
try {
|
||||
if (!ok) {
|
||||
|
|
|
@ -33,6 +33,23 @@ function f3(m: { foo(): void }, p: { foo: () => void }, r: { readonly foo: () =>
|
|||
p = r; // Error
|
||||
}
|
||||
|
||||
interface Base {
|
||||
foo(): void;
|
||||
}
|
||||
|
||||
interface Item extends Base {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface ReadonlyItem extends Base {
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
declare let item1: ReadonlyItem;
|
||||
declare let item2: Readonly<Item>;
|
||||
|
||||
item1 = item2;
|
||||
|
||||
type Paths = string[] & { __brand__: "Paths" };
|
||||
|
||||
function f4(rp: Readonly<Paths>, rs: Readonly<string[]>) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче